-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.txt
31 lines (21 loc) · 1.59 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
A java.lang.ThreadLocal allows linking / un-linking of any kind of object to an externally controlled java.lang.Thread.
The linked object must be seen as a specific thread resource linked to a specific business workflow ( execution context ).
Examples of execution contexts : business transactions, database transactions, security contexts data, user request context data.
java.lang.ThreadLocal can be used when the running thread actual runnable class cannot be controlled or defined
thus the running thread cannot be linked with a custom running context via a simple class field reference.
A java.lang.ThreadLocal acts as a java.util.Map < java.lang.ref.WeakReference < java.lang.Thread > , java.lang.Object >
A java.lang.ThreadLocal always uses the current thread object as map key for all operations performed.
Current thread is obtained via java.lang.Thread.currentThread.
It is the responsibility of the developer to ensure proper thread resource linking and un-linking.
See :
- http://tutorials.jenkov.com/java-concurrency/threadlocal.html
- java.lang.ThreadLocal
Exercise :
Test a ThreadLocal on a single thread
Test a ThreadLocal over a couple of running in parallel threads.
Info :
Application servers maintain a pool of threads used by the deployed applications
The pool of threads is managed by the application server only
For each user request the application server allocates a thread to process the user request
The application server links a user request context to the processing thread
The application server un-links the user request context to the processing thread once the user request is processed