This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi How can we get the time a servlet get a request, and the time when servlet finishes (so that by subtracting them we get the elapsed time for what was've done inside the servlet)? is there any method like onStart and onEnd so that we can capture these times inside them? Thank's. Pourang
Dear Steve In advanced, I'd like to appreciate you for replying to my question. After considering your technical bio I should tell it was an absolute honor for me to get my answer from a real pro like you. Best Regards, Pourang Emami
Hello Pourang Emami, At the start of your servlet,use System.currentTimeMillis() which returns long and at the end of it,use the same method and subtract the both,u will get the time taken by the servlet to serve the request.Hope it will help u. Regards, Ravi
Joined: Jun 26, 2002
JAMon and System.currentTimeMillis() are similar, but JAMon offers many advantages over the latter. First of all the timings using currentTimeMillis() are stuck in your application. Of course you can write them to a log or display them, but what about average, min and max times. Also, what if you want to measure many things such as every one of your pages, database connections, session times, and more. After a while looking through a log to collect these various times becomes a burden, if you are lucky enough to have access to your applications logs. One surprising advantage of JAMon is that it is easier to use than currentTimeMillis(). Remembering start() and stop() is easier than creating a start time and end time and subtracting them. With JAMon just get the 90K Jar in your classpath and start making calls. Within minutes you will have your numbers. Good luck. Let me know how it works out. steve - http://www.jamonapi.com
Joined: Sep 21, 2002
Hi my friends Actually at first I tried GregorianCalendar Cal1 = new GregorianCalendar(); long t1 = Cal1.getTime().getTime(); instead of System.currentTimeMillis() in a very simple typical servlet that just generated a html page containig some simple text like "Hello World" . I put "long t1 = Cal1.getTime().getTime();" before the codes generating the html and another one after it(had both them printed on the console for checking purpose), but I got "t1 - t2 = 0". The servlet first generated the html and after that I would get t1 , t2 printed on the console at the same time so the subtraction was 0? But with System.currentTimeMillis() and JAMon I got the desired result. I am so interested to know why? (Any way, I introduced JAMon to my co-workers because I think Steve has done a very good job on it.) Best Regards, Pourang