• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Getting timestamp for a new Http request?  RSS feed

Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want to do is get the timestamp in milliseconds (epoch) for my request when it lands in the interceptor. I have a HttpServletRequest request variable. I thought of invoking request.getDateHeader() but it asks for the name of the header and I'm not sure how to retrieve that from the request.
Posts: 63461
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you extract the header's name from the result of this method?
Saloon Keeper
Posts: 20510
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's just so much fuzz in there. Any network request is actually smeared out over time. The time the client opened the request connection, the time when the last byte of the request left the client (and note that that client's clock may be wrong!), the time it got queued up in the server, time to digest it into actual JEE component objects, the time it actually gets dispatched (which can be delayed if the processing thread pool is backed up.

Also, HTTP itself carries no timestamp, so you're going to have to measure from outside.

In most cases, I consider it sufficient to grab the time of day in the beginning of the servlet request execution method (e.g., doGet()). If the request initiates persistent data storage operations, I let the database worry about the actual time that the transaction was committed. And, of course, if the point is to see how fast a request can be processed, I'll take a time snapshot right before I exit the servlet request method.

Don't forget - if you're using a logger, the logger itself usually timestampts log entries.
You don't like waffles? Well, do you like this tiny ad?
Become a Java guru with IntelliJ IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!