KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jzonic > jlo > TimeTracker


1 package org.jzonic.jlo;
2
3 public class TimeTracker {
4
5     private static ThreadLocal JavaDoc trackers = new ThreadLocal JavaDoc();
6     
7     public static void start() {
8         TimeTrackerObject tto = (TimeTrackerObject)trackers.get();
9         if ( tto == null ) {
10             tto = new TimeTrackerObject();
11         }
12         trackers.set(tto);
13     }
14     
15     public static void stop() {
16         trackers.set(null);
17     }
18     
19     public static long getEllapsedTime() {
20         TimeTrackerObject tto = (TimeTrackerObject)trackers.get();
21         if ( tto != null ) {
22             return tto.getEllapsedTime();
23         }
24         return 0;
25     }
26     
27     public static boolean isTracking() {
28         TimeTrackerObject tto = (TimeTrackerObject)trackers.get();
29         if ( tto != null ) {
30             return true;
31         }
32         return false;
33     }
34
35     public static TimeTrackerObject get() {
36         return (TimeTrackerObject)trackers.get();
37     }
38
39 }
40
Popular Tags