...
These variables differ from their normal counterparts in that each thread that accesses one (via its
get
orset
method) has its own, independently initialized copy of the variable. ThreadLocal instances are typicallyprivate static
fields in classes that wish to associate state with a thread (e.g.for example, a user ID or Transaction ID).
...
The DiaryPool
class creates a thread pool that reuses a fixed number of threads operating off a shared, unbounded queue. At any point, at most, NoOfThreads
threads are actively processing tasks. If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available. The thread-local state of the thread persists when a thread is recycled.
...