multithreading - Java Thread.sleep waking up "much" earlier than the scheduled time -


i have requirement of writing daemon initiates number of threads wakes @ different times. daemon written in java using commons apache library , run on linux machine (fedora 13 ). 1 thread wakes everyday perform task happens scheduled. there thread scheduled wake every monday @ 6 perform task not happen scheduled. problem thread wakes before actual scheduled time. runs 2 days after completion of previous run though should run after week. waiting time calculated correctly using our own timer class , because reuses existing code not see problem in this.

what problem here?

thanks

thread.sleep() doesn't make guarantees, , might wake earlier expected. should use in loop:

long curtime = system.currenttimemillis();  while (wakeuptime - curtime > 0) {   try {     thread.sleep(wakeuptime - curtime);   } catch (interruptedexception ex) { }   curtime = system.currenttimemillis(); } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -