Hello. I'm having trouble with obtaining the current second from my servlet.
As you can see, the code looks totally fine. But, actually, the problem is when I'm running it in my browser (Chrome) the seconds are correct. However, at times it actually skips a second, which is messing up parts of my application.
When I use System.nanoSeconds() I've noticed every time I get the current time (using an auto refresher - refresh every second) a few of the milli digits are actually increasing every seconds the auto refresh kicks in. Eventually, the servlet skips a second.
Any tips please? The code you see is the only code that's actually running.
Have you debugged the servlet? Is there a new GET request every 1 second? I think that it could be a network or client problem. The auto refresher probably is some kind of client script that refreshes the page every interval. It could also be a problem on the auto refresher.
Joined: Feb 08, 2011
Oli Wurster wrote:Have you debugged the servlet? Is there a new GET request every 1 second? I think that it could be a network or client problem. The auto refresher probably is some kind of client script that refreshes the page every interval. It could also be a problem on the auto refresher.
Thanks for the reply. There's a get request every second. This is running on my localhost machine (until deployment).
Do you think there can be a performance hit when running GlassFish on a localhost machine? Rather than a dedicated
server? Personally, I think its because my dev-machine. Its kinda slow and crap to run GlassFish
Joined: Mar 09, 2012
Unfortunately I can't say anything about performance on Glassfish. But I don't think it is the server. I rather think it is a timing problem. Imagine the following: The client requests to the server every second (with a precision of some micro-seconds). Then there is the transport of the request (TCP/IP) to the server, that takes some microseconds on localhost. Now if two requests are send by the client, the first arrives just before a certain time, for example on 16:00:00.999, the next request shoud be on 16:00:01.999, but is just a few micro seconds later. then the response will be 16:00:02.004 (ore something). This makes it look like the server time jumps sometime. This is just a theory. Try to write the exact times to the console or the logs on Glassfish.
phillip nash wrote:There's a get request every second.
Have you confirmed that this is happening precisely once per second? And how precisely is it happening? And have you confirmed that there are no network delays which reduce the precision of that measurement? And no delays in your server either?
You suggest that there's a problem in your application if a certain piece of code doesn't run exactly once per second. I wouldn't choose sending a GET request from a client system to fulfil that requirement -- but perhaps I didn't understand your requirement.