Java and Javascript System.currentTimeMillis() not compatible?
801782Sep 30 2010 — edited Sep 30 2010Hi 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.