Set an absolute time for a thread to sleep
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, March 27, 2002 02:35 PM

Does anyone know how I can make a Thread sleep for an absolute time?
e.g: till Friday Mar 29th 2002. I can't use time in milliseconds since the process will need to recover and run only till the specified date and time if the system crashes. Thanks

Re: Set an absolute time for a thread to sleep

Posted By:   Geoff_Lane  
Posted On:   Saturday, March 30, 2002 09:32 AM

To get the difference between now and some date in the future for a sleep call you can do something like:


long current = System.currentTimeMillis();
Calendar cal = new Calendar();
cal.set(2002, 2, 29, 5 25);

long future = cal.getTimeInMillis();

sleep(future - current);


Probably want some error checking to make sure that the calendar date is after the current time, etc. But you get the idea?

Re: Set an absolute time for a thread to sleep

Posted By:   Edward_Harned  
Posted On:   Thursday, March 28, 2002 11:38 AM

Thread.sleep() only has milliseconds [and nanoseconds].



You can calculate the number of milliseconds from now until then and use that in sleep(). But you are asking something else that I don't understand.



What do you mean "will need to recover and ..."?

About | Sitemap | Contact