Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Thread,sleep(n) doesn't sleep for n!!

Squall867Jun 24 2012 — edited Jun 25 2012
Hi, I'm getting crazy trying to understand this problem...I have a multi threaded program with a queue and 2 methods, enter() and exit() which allow to enter/exit from it.
Between enter() and exit() a thread has to wait for 100ms, so the sequence is:
long time = System.currentTimeMillis();
queue.enter();
Thread.sleep(100);
queue.exit();
time = System.currentTimeMillis() - time;
just one thread at time can enter in queue so, in the end, I should have something like
t1 = 100+x (x is a plus for other operations)
t2 = 200+x
t3 = 300+x

but I obtain, instead, something like
t1 = 100+x
t2 = 195 +x
t3 = 264 +x

...how come? t2 should be AT LEAST 200!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 23 2012
Added on Jun 24 2012
5 comments
274 views