Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6562495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:42:57+00:00 2026-05-25T13:42:57+00:00

In my valve I get the execution time of my http query like that

  • 0

In my valve I get the execution time of my http query like that :

public void invoke(Request request, Response response) 
throws IOException, ServletException {
long t1 = System.currentTimeMillis();
getNext().invoke(request, response);
long t2 = System.currentTimeMillis();
long time = t2 - t1;
...
}

I suspect that the time I get this way, not only give me the server side execution time but also the network time ? Is it possible ?

(Because depending on the client who do the request the average time measured is not the same from one ip I have 70ms average time and another ip 270ms)

I have written the exact same code in a Filter:

long before = System.currentTimeMillis();
chain.doFilter(request, response);
long after = System.currentTimeMillis();

, but in my test the execution time in the Valve and in the filter are the same…

I am more interested in getting the execution time of my servlet only.
But if I could get also the time when the last byte is sent, I would be interested.

Thanks a lot to clarify me what is possible to know with valves and filters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:42:58+00:00Added an answer on May 25, 2026 at 1:42 pm

    I suspect that the time I get this way, not only give me the server side execution time but also the network time ? Is it possible ?

    That’s correct. At least, a partial of the network time involving transferring the request body is included in the total time this way. The valve/filter/servlet code get invoked directly once the request headers have been fully read and parsed. The request body is not necessarily fully read at that point. The request body contains whatever the client sends over network as part of the request (e.g. submitted form data). Only when the filter/servlet starts to read and parse the full request body by e.g. getParameter(), getReader(), getInputStream(), etc, then all the bytes of the request body will actually be transferred.

    You may want to rewrite your execution time measurement in such way that it only starts after the request body has been fully read. This means that you really have to measure it right inside the servlet.

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // Read the request body.
        String foo = request.getParameter("foo");
        String bar = request.getParameter("bar");
        // ...
    
        // Now, start the stopwatch.
        long startTime = System.nanoTime();
    
        // Now, do the business job.
        someService.process(foo, bar, ...);
        // ...
    
        // Now, stop the stopwatch.
        long elapsedTime = System.nanoTime() - startTime;
    
        // I don't think that you want to include JSP rendering in total time, right?
        request.getRequestDispatcher("/WEB-INF/some.jsp").forward(request, response);
    }
    

    (note that I used System#nanoTime() as it has a much better accuracy)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have noticed that regardless of a given script's execution time, every date() call
when selecting a column that can contains a NULL value I get an exception
From http://csharpindepth.com/Articles/Chapter8/PropertiesMatter.aspx using System; struct MutableStruct { public int Value { get; set; }
def confirmemail(request,token): user = Users.objects.get(email_token = token) if user: user.email_token = '' user.email_token_expiry =
I want to enter to administration application of my site. on request: http://mysite.ru/admin/ -
I have a table that looks like this: category category_id name category_seo_friendly_url left_id right_id
I have a google map javascript link like: string GoogleURL = http://maps.google.com/maps?file=api&v=2&key=abcdefg I built
I'm getting an error: ImportError at / No module named lxml Request Method: GET
I am running this Powershell command: Get-counter -Counter \Processor(_Total)\% Processor Time –Continuous Which I
Trying to get radiobuttons binding working but getting a run time error with the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.