Link to home
Start Free TrialLog in
Avatar of SpenceMan
SpenceMan

asked on

Microsecond accuracy in Java

I am building a device that uses a Parallax PING sensor. I would like to be able to use Java to control the PING because I have a Java 3D environment. I can communicate with the PING but I have not found a way to get the resolution I need (microseconds). nanoTime() has the precision but not the accuracy, at least the way I am implementing it. Any ideas on what I can do?
Avatar of Venabili
Venabili
Flag of Bulgaria image

On the question - I am afraid that you cannot do anything about it in Java. And the Javadoc of System.nanoTime() actually says it pretty clearly: "This method provides nanosecond precision, but not necessarily nanosecond accuracy"

And there is no other method that can help you.

Sorry :(
Avatar of CEHJ
You might try making a native system call if the OS supports it
Yeah, I was thinking about it

Even if it does support it, I suspect it will take at least a millisecond to get processed via JNI (or whatever is used to call it) so it won't be better than just using the milliseconds we have... Or even if it is not a full millisecond, it will still be off.... that's why I do not think that the accuracy can be achieved...
Avatar of SpenceMan
SpenceMan

ASKER

I have heard people talk about the library javax.realtime and people using it, but it is no where to be found. Sort of like Big Foot. Any info on that?

For right now I ended up getting a micro controller that I can program in C to communicate with the sensors separately from the java program. It get's the job done.
ASKER CERTIFIED SOLUTION
Avatar of Venabili
Venabili
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PS: You know that it is not supported on most OSs, right?