Computing.Net > Forums > Programming > To allow a thread sleep for microseconds

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

To allow a thread sleep for microseconds

Reply to Message Icon

Name: Anand BVKS
Date: September 30, 2009 at 16:59:57 Pacific
OS: Windows Vista
Subcategory: Java
Comment:

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..



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: September 30, 2009 at 17:56:37 Pacific
Reply:

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


2

Response Number 2
Name: Razor2.3
Date: September 30, 2009 at 18:50:24 Pacific
Reply:

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().)


1

Response Number 3
Name: StuartS
Date: October 1, 2009 at 04:32:38 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: To allow a thread sleep for microseconds

VBScript to launch a secure website login www.computing.net/answers/programming/vbscript-to-launch-a-secure-website-login/20230.html

need to create a firewall in window www.computing.net/answers/programming/need-to-create-a-firewall-in-window/3833.html

Execute a program once for all user www.computing.net/answers/programming/execute-a-program-once-for-all-user/4711.html