The Artima Developer Community
Sponsored Link

Java Answers Forum
Can a JDK 1.4 thread sleep in nanosecond time?

1 reply on 1 page. Most recent reply: Mar 23, 2007 10:20 AM by Parag Shah

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Parag Shah

Posts: 24
Nickname: parags
Registered: Mar, 2003

Can a JDK 1.4 thread sleep in nanosecond time? Posted: Mar 23, 2007 10:18 AM
Reply to this message Reply
Advertisement
JDK 1.4 did not have any methods to report time in ns, but can it's internal counter manage nanosecond time?

For example will the following code put the thread to sleep for 50 ns or will it be a minumum of 1 ms?
Thread.sleep(0, 50);


The following code gives me an output of 15 ms on my computer.
long t1 = System.currentTimeMillis();
for(int i=0; i<8;i++) {
    Thread.sleep(0, 500000);
}
long t2 = System.currentTimeMillis();
System.out.println("Time for sleeping 8 time * 500000 ns: " + (t2-t1));

This seems to suggest that the thread is capable of sleeping in nanosecond time.

Can anyone shed some light on the matter.

Thanks
Parag


Parag Shah

Posts: 24
Nickname: parags
Registered: Mar, 2003

Re: Can a JDK 1.4 thread sleep in nanosecond time? Posted: Mar 23, 2007 10:20 AM
Reply to this message Reply
oops... I meant to say

This seems to suggest that the thread may not be capable of sleeping in nanosecond time.

Flat View: This topic has 1 reply on 1 page
Topic: Can a JDK 1.4 thread sleep in nanosecond time? Previous Topic   Next Topic Topic: java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use