Packages

t

org.apache.spark.util

LexicalThreadLocal

trait LexicalThreadLocal[T] extends AnyRef

Helper trait for defining thread locals with lexical scoping. With this helper, the thread local is private and can only be set by the Handle. The Handle only exposes the thread local value to functions passed into its runWith method. This pattern allows for the lifetime of the thread local value to be strictly controlled.

Rather than calling tl.set(...) and tl.remove() you would get a handle and execute your code in handle.runWith { ... }.

Example:

object Credentials extends LexicalThreadLocal[Int] {
  def create(creds: Map[String, String]) = new Handle(Some(creds))
}
...
val handle = Credentials.create(Map("key" -> "value"))
assert(Credentials.get() == None)
handle.runWith {
  assert(Credentials.get() == Some(Map("key" -> "value")))
}
Source
LexicalThreadLocal.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LexicalThreadLocal
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. final class Handle extends AnyRef

    Final class representing a handle to a thread local value.

Value Members

  1. def get(): Option[T]