Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added exception

...

Unmodifiable classes whose design incorporates ThreadLocal data should not be executed in thread pools.

Exceptions

EX1: Sometimes the state of the ThreadLocal object does not change beyond its initial value. For example, there may be only one type of database connection represented by the initial value of the ThreadLocal object. In the absence of mutability, it is safe to use a thread pool.

Risk Assessment

When objects of classes that use ThreadLocal data are executed in a thread pool by different threads, they may assume stale states, resulting in corrupt data.

...