01: /**
02: *
03: */package clime.messadmin.filter;
04:
05: import java.util.Date;
06:
07: /**
08: * ThreadLocal containing some interesting data for internal usage.
09: * An alternative would be to put data into the request, but this could look like pollution...
10: * @author Cédrik LIME
11: */
12: public class MessAdminThreadLocal {
13: private static final ThreadLocal/*<Date>*/startTime = new ThreadLocal/*<Date>*/();
14: private static final ThreadLocal/*<Date>*/stopTime = new ThreadLocal/*<Date>*/();
15:
16: /**
17: *
18: */
19: private MessAdminThreadLocal() {
20: super ();
21: }
22:
23: public static void start() {
24: startTime.set(new Date());
25: }
26:
27: public static void stop() {
28: stopTime.set(new Date());
29: }
30:
31: public static void remove() {
32: //startTime.remove();
33: //stopTime.remove();
34: startTime.set(null);
35: stopTime.set(null);
36: }
37:
38: public static Date getStartTime() {
39: Date date = (Date) startTime.get();
40: // Workaround for bug of BEA Weblogic 8.1.5 / Java 1.4.2_05 / XP
41: return date != null ? date : new Date(0);
42: }
43:
44: public static Date getStopTime() {
45: Date date = (Date) stopTime.get();
46: // Workaround for bug of BEA Weblogic 8.1.5 / Java 1.4.2_05 / XP
47: return date != null ? date : new Date(0);
48: }
49:
50: public static int getUsedTime() {
51: try {
52: return (int) (getStopTime().getTime() - getStartTime()
53: .getTime());
54: } catch (NullPointerException npe) {
55: // Workaround for bug of BEA Weblogic 8.1.5 / Java 1.4.2_05 / XP
56: //e.printStackTrace();
57: return 0;
58: }
59: }
60: }
|