Class RequestTimeThreadLocal
- java.lang.Object
-
- com.atlassian.confluence.core.datetime.RequestTimeThreadLocal
-
public class RequestTimeThreadLocal extends Object
A thread-local for storing the time a request was received. This timestamp can be used for consistent date-time handling across all operations performed within the scope of a single request.- Since:
- 2.7
-
-
Constructor Summary
Constructors Constructor Description RequestTimeThreadLocal()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
clearTime()
Clears the stored value of the thread-local.static long
getTime()
Retrieves the value of the request time thread-local.static Date
getTimeOrNow()
Returns the value of the request time thread-local converted to a new Date object.static void
setTime(long currentTimeMillis)
Sets the value of the thread-local.
-
-
-
Method Detail
-
setTime
public static void setTime(long currentTimeMillis)
Sets the value of the thread-local. Should not be called by application code, but rather by a servlet filter which handles each request.- Parameters:
currentTimeMillis
- the timestamp to store, measured in milliseconds since the epoch defined byDate(long)
.
-
clearTime
public static void clearTime()
Clears the stored value of the thread-local. Should not be called by application code, but rather by the finally block in the servlet filter which callssetTime(long)
.
-
getTime
public static long getTime()
Retrieves the value of the request time thread-local. The value is measured in milliseconds since the epoch defined byDate(long)
.- Returns:
- the value of the request time thread-local, or -1 if it has not been set.
-
getTimeOrNow
public static Date getTimeOrNow()
Returns the value of the request time thread-local converted to a new Date object. If the thread-local is not set, returns a new Date representing the current time.- Returns:
- a Date with the time stored in the thread-local, or the a new Date with the current time if the thread-local is not set.
-
-