KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > util > Timer


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.util;
6
7
8 /**
9  * A bean that can be used to time execution of pages
10  *
11  * @author Rickard Öberg (rickard@middleware-company.com)
12  * @version $Revision: 1.3 $
13  */

14 public class Timer {
15     //~ Instance fields ////////////////////////////////////////////////////////
16

17     // Attributes ----------------------------------------------------
18
long current = System.currentTimeMillis();
19     long start = current;
20
21     //~ Methods ////////////////////////////////////////////////////////////////
22

23     // Public --------------------------------------------------------
24
public long getTime() {
25         // Return how long time has passed since last check point
26
long now = System.currentTimeMillis();
27         long time = now - current;
28
29         // Reset so that next time we get from this point
30
current = now;
31
32         return time;
33     }
34
35     public long getTotal() {
36         // Reset start so that next time we get from this point
37
return System.currentTimeMillis() - start;
38     }
39 }
40
Popular Tags