To allow a thread sleep for microseconds

September 30, 2009 at 16:59:57
Specs: Windows Vista
Can a thread in java be allowed to sleep for microseconds ...say 605.4micro seconds???
sleep(long millis) or
sleep(long millis,int nanos)
is generally accepted...
so how do i allow it sleep for a fractional number in microseconds
ex== 607.5 micro seconds...


please help me out
Thank you..


See More: To allow a thread sleep for microseconds

Report •


#1
September 30, 2009 at 17:56:37
No point as there is nothing to be gained. The real time clock hardware in a PC only has a resolution of 150 microseconds so a time of 607 microseconds is only going to be accurate to +_ 75 microseconds ,

To get the resolution you are looking for you would need a real time clock interrupt every ten nano seconds. Just not possible and leave time to do anything else. The only devices that can provide that degree of resolution and accuracy are atomic clocks.

Stuart


Report •

#2
September 30, 2009 at 18:50:24
Anand BVKS: how do i allow it sleep for a fractional number in microseconds
1000 nanoseconds = 1 millisecond.

But on PC's, as StuartS says, be careful of sleep. Every function of sleep should be very specific about what it guarantees.

For instance, Win32's Sleep() guarantees to mark the thread unrunnable for at least the specified interval, ± 1 CPU tick.

POSIX usleep() guarantees to keep the thread from running for at least the specified interval, as long as certain signals are not sent to it.

Java's Thread.sleep() won't even give you that much. Java doesn't guarantees the same "at least" mechanics as the previous two. A thread might even wake up early.

(For reference, .NET's Thread.Sleep() just calls Win32's SleepEx().)


Report •

#3
October 1, 2009 at 04:32:38
1000 milliseconds = 1 second 1 thousand
1000 microseconds = 1 millisecond 1 million
1000 nanoseconds = 1 microsecond 1 billion
1000 picoseconds = 1 nanosecond 1 trillion

Stuart


Report •

Related Solutions


Ask Question