Alternatives to Thread.sleep()
Hi Guys,
Is there a different way of letting my class wait for 10 seconds instead of using Thread.sleep(). I can't use Thread.speep() as it keeps getting Interrupted and comming out off sleep. It is a multithreaded application, with threads listining on other threads, so I can't use sleep() method
Thankyou
Sunath Kodali
[348 byte] By [
vazraa] at [2007-11-27 10:43:49]

You need to revist what you are doing here. Like review the following
- what is interrupting your thread and why?
- why are you not waiting?
Hmm....
<obnoxious>
void reallyInefficientSleep(long millis) {
long now = new Date().getTime();
long eventually = now + millis;
while(new Date().getTime() < eventually) {}
}
</obnoxious>
Use a socket read or accept or connect timeout. Use Object.wait(timeout). Use java.util.concurrent.Semaphore.tryAcquire(permits, timeout, ...).
IOW Thread.sleep() is probably not the right tool for the job, whatever that may be.
ejpa at 2007-7-28 20:02:59 >
