View Javadoc

1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.core.util;
17  
18  /**
19   * Thread Local Timer for Tread Safe Request Logging {@see RequestLoggingFilter}
20   * @author Kuali Rice Team (rice.collab@kuali.org)
21   */
22  public class ThreadLocalTimer {
23      /**
24       * startTimeThreadLocal ThreadLocal<Long>
25       */
26      public static ThreadLocal<Long> startTimeThreadLocal = new ThreadLocal<Long>();
27  
28      /**
29       * Returns startTimeThreadLocal as long since epoch
30       * @return long since epoch
31       */
32      public static long getStartTime() {
33          return (Long)startTimeThreadLocal.get();
34      }
35  
36      /**
37       * Sets startTimeThreadLocal to the given long since epoch.
38       * @param dateTime long since epoch
39       */
40      public static void setStartTime(long dateTime) {
41          startTimeThreadLocal.set(Long.valueOf(dateTime));
42      }
43  
44      /**
45       * Cleanup, startTimeThreadLocal.remove()
46       */
47      public static void unset() {
48          startTimeThreadLocal.remove();
49      }
50  }