Allahjane
Allahjane

Reputation: 1978

Is sleep method accurate in timing precision?

We all know of sleep method available in java threads.. I understand that the precision in timing depends on the precision of hardware clock in the system.. So my question is how accurate is this method or better say what is the error in milliseconds or nanoseconds considering a general pc.

My requirement its to synchronise data transfer using sleep for timing.. The data is to be sent in fixed in intervals (10-20 millis) and if there is a delay of more than 1sec due to successive error in timing it may be bad !

So is it advisable to use the also method?

Upvotes: 1

Views: 1024

Answers (2)

Peter Lawrey
Peter Lawrey

Reputation: 533680

If you need to synchronize data, I suggest you do this yourself rather than relying on threads to wake up at preset times. i.e. use one thread to simulate when events occur, in the order you expect them to occur.

Upvotes: 1

marktani
marktani

Reputation: 7808

Sleep is not the thing you want, as in here. I suggest to read through this.

Upvotes: 1

Related Questions