public class

RequestTimeThreadLocal

extends Object
java.lang.Object
   ↳ com.atlassian.confluence.core.datetime.RequestTimeThreadLocal

Class Overview

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.

Summary

Public Constructors
RequestTimeThreadLocal()
Public Methods
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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public RequestTimeThreadLocal ()

Public Methods

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 calls setTime(long).

public static long getTime ()

Retrieves the value of the request time thread-local. The value is measured in milliseconds since the epoch defined by Date(long).

Returns
  • the value of the request time thread-local, or -1 if it has not been set.

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.

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 by Date(long).