Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Wiki Markup
The {{java.lang.ThreadLocal<T>}} class provides thread-local variables. According to the Java API \[[API 06|AA. Java References#API 06]\]:

This class These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, independently initialized copy of the variable. ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread (e.g., a user ID or Transaction ID).

...

This compliant solution uses a custom ThreadPoolExecutor that extends ThreadPoolExecutor and overrides the beforeExecute() method. This method is invoked before the Runnable task is executed in the specified thread to reinitialize the thread local variable before task r is executed by thread t.

...