• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java time with servlet in-accurate

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
phillip nash
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Oli Wurster
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

You could sync the time every minute (or every 10 minutes) and use the JavaScript Date object on the Page it self. This way you would have less network traffic. If the app will be running over a network (instead of localhost only) There will be a bigger problem with the time the request and response use.

I hope that helps.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you doing? making some sort of Time Server?
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic