Package jadex.future
Class ThreadLocalTransferHelper
java.lang.Object
jadex.future.ThreadLocalTransferHelper
- Direct Known Subclasses:
ThreadSuspendable
Helps to transfer registered thread local values between different threads.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Set
<ThreadLocal<Object>> The registered thread locals.protected Map
<ThreadLocal<Object>, Object> The thread locals. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new transfer helper.ThreadLocalTransferHelper
(boolean beforeswitch) Create a new transfer helper. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addThreadLocal
(ThreadLocal<?> tl) Add a thread local that will be automatically copied on thread resumption.void
Must be called after a thread switch occurs to restore the thread local values.void
Must be called before a thread switch occurs to save the thread local values.static void
removeThreadLocal
(ThreadLocal<?> tl) Add a thread local that will be automatically copied on thread resumption.static void
restoreValues
(Map<ThreadLocal<Object>, Object> vals) Method to be called on new thread on resumption.static Map
<ThreadLocal<Object>, Object> Method to be called on old thread before thread switch.
-
Field Details
-
THREADLOCALS
The registered thread locals. -
vals
The thread locals.
-
-
Constructor Details
-
ThreadLocalTransferHelper
public ThreadLocalTransferHelper()Create a new transfer helper. -
ThreadLocalTransferHelper
public ThreadLocalTransferHelper(boolean beforeswitch) Create a new transfer helper.
-
-
Method Details
-
saveValues
Method to be called on old thread before thread switch. -
restoreValues
Method to be called on new thread on resumption. -
addThreadLocal
Add a thread local that will be automatically copied on thread resumption. -
removeThreadLocal
Add a thread local that will be automatically copied on thread resumption. -
beforeSwitch
public void beforeSwitch()Must be called before a thread switch occurs to save the thread local values. -
afterSwitch
public void afterSwitch()Must be called after a thread switch occurs to restore the thread local values.
-