ThreadLocal

final class ThreadLocal[A]

Cross-platform equivalent for java.lang.ThreadLocal, for specifying thread-local variables.

These variables differ from their normal counterparts in that each thread that accesses one (via its ThreadLocal#get or ThreadLocal#set method) has its own, independently initialized copy of the variable.

Value parameters:
initial

is the initial value that this thread-local reference returns on reads in case the current thread hasn't written any values yet.

Companion:
object
class Object
trait Matchable
class Any

Value members

Concrete methods

def get(): A

Returns the value in the current thread's copy of this thread-local variable. If the variable has no value for the current thread, it is initialized with the initial value specified in the constructor.

Returns the value in the current thread's copy of this thread-local variable. If the variable has no value for the current thread, it is initialized with the initial value specified in the constructor.

Returns:

the current thread's value of this thread-local

def reset(): Unit

Removes the current thread's value for this thread-local variable. If this thread-local variable is subsequently read by the current thread, its value will be reinitialized by its initial value.

Removes the current thread's value for this thread-local variable. If this thread-local variable is subsequently read by the current thread, its value will be reinitialized by its initial value.

def set(value: A): Unit

Sets the current thread's copy of this thread-local variable to the specified value.

Sets the current thread's copy of this thread-local variable to the specified value.

Value parameters:
value

the value to be stored in the current thread's copy of this thread-local.

Concrete fields

val initial: A