A method of copying context to threads created by a ThreadFactory for use by an ExecutorService.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
threadcontextcopy
threadcontextcopyexamples
.gitignore
.travis.yml
LICENSE
README.md
pom.xml

README.md

Build Status License

Thread Context Copy

A method of copying context to threads created by a ThreadFactory for use by an ExecutorService.

Sometimes it is necessary to copy context in the form of ThreadLocal storage across the threads used by an ExecutorService. An example could be when managing cookies to be attached to multiple concurrent calls to a webservice.

At the point where the concurrent tasks should be executed, construct an ExecutorService which uses the ContextCopyingThreadFactory. This ThreadFactory is itself constructed with a Collection of ContextCopier implementations. The ContextCopiers are responsible for copying or capturing the contextual information on the initial thread and applying the contextual information onto the new threads created by the ThreadFactory.

Example

Class ExecutorServiceExample demonstrates how thread-specific storage (using Log4J2's ThreadContext) can be copied to a Thread created by the ContextCopyingThreadFactory.