This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Getting timestamp for a new Http request?  RSS feed

 
Greenhorn
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.
 
Marshal
Posts: 62194
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you extract the header's name from the result of this method?
 
Bartender
Posts: 20107
101
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.
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!