By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,469 Members | 1,885 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,469 IT Pros & Developers. It's quick & easy.

Thread.sleep

P: n/a
Uri
I would like to describe the following scenario:

1. Start a thread which write something to the screen every 5 seconds
(the thread uses the sleep method by Thread). current Windows time is
15:00.
2. change the Windows clock backwards. current time is: 14:00.
3. the thread doesn't wake up.
4. wait untill 14:01.
5. change the Windows clock forward to 16:00.
6. the thread wakes up the amount of times it missed in a row (in this
case 20 times).

Are you familier with this behaviour ?
Can you tell us what causes this ?
And the Milion dolar question: How can we overcome this issue ????
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
bu****@motorola.com (Uri) wrote in
news:6d**************************@posting.google.c om:
I would like to describe the following scenario:

1. Start a thread which write something to the screen every 5 seconds
(the thread uses the sleep method by Thread). current Windows time is
15:00.
2. change the Windows clock backwards. current time is: 14:00.
3. the thread doesn't wake up.
4. wait untill 14:01.
5. change the Windows clock forward to 16:00.
6. the thread wakes up the amount of times it missed in a row (in this
case 20 times).

Are you familier with this behaviour ?
Can you tell us what causes this ?
And the Milion dolar question: How can we overcome this issue ????


I believe that Java keeps track of wakeup times on an absolute basis. Thus,
the thread (step 1) will not wake up until the time is greater than or equal
to 15:00:05. This doesn't occur until Step 5.

I can't explain Step 6, but I don't understand your comment about 20 times.
20 x 5 seconds = 100 seconds, not one minute or one hour or two hours.
--
Ian Shef
These are my personal opinions and not those of my employer.
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.