Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java and Javascript System.currentTimeMillis() not compatible?

801782Sep 30 2010 — edited Sep 30 2010
Hi all,

I have a simple httpServer class that accepts requests from a AJAX web page.

The javascript;


var d = new Date();
var Ctime = d.getTime();

this is then sent as a XMLHttpRequest to the server,

the server then calls
long Stime = System.currentTimeMillis();

then the latency is calculated as Stime-Ctime.

Now the thing is that most of the time the latency is 0-10 ms, however once or twice the latency has been calculated as -1ms!

How is this possible? My understanding is that Javascript runs on a single thread and the variable Ctime is encoded into the request so Ctime must actually occur before Stime!

Grateful to anyone who can explain this! Also welcome addition suggestions for calculating latency in this regard.

Thanks in advance,

Joe.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 28 2010
Added on Sep 30 2010
10 comments
2,033 views