Reputation: 19579
after the timeout, the thread will also need to compete for the own of the monitor or the lock.
then, at the worst case, this could be a long time, and much longer then the timeout
is it?
Upvotes: 0
Views: 51
Reputation: 41188
Yes. You have no guarantee when the thread will next execute. Just that it will happen sometime after the sleep time
Things like the ScheduledExecutorService
mitigate this with scheduleAtFixedRate
but they still cannot guarantee that it will run exactly at that time.
To avoid this you need a Real Time Operating System.
However in practice most computers are fast enough that this just isn't an issue unless you are doing something that is incredibly time-critical. The thread will execute within miliseconds of your desired time most of the time.
Upvotes: 3