|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ThreadState
A ThreadState
instance manages any state that might need to be bound and/or restored during a thread's
execution.
bind()
will place state on the currently executing thread to be accessed later during
the thread's execution.
restored
to guarantee all threads stay clean in any thread-pooled environment. This should always
be done in a try/finally
block:
ThreadState state = //acquire or instantiate as necessary try { state.bind(); doSomething(); //execute any logic downstream logic that might need to access the state } finally { state.restore(); }
Method Summary | |
---|---|
void |
bind()
Binds any state that should be made accessible during a thread's execution. |
void |
clear()
Completely clears/removes the ThreadContext state. |
void |
restore()
Restores a thread to its state before bind bind was invoked. |
Method Detail |
---|
void bind()
try/finally
block paired with the restore()
call to guarantee that the thread
is cleanly restored back to its original state. For example:
ThreadState state = //acquire or instantiate as necessary try { state.bind(); doSomething(); //execute any logic downstream logic that might need to access the state } finally { state.restore(); }
void restore()
bind
was invoked. This should typically always be
called in a finally
block to guarantee that the thread is cleanly restored back to its original state
before bind
's bind was called. For example:
ThreadState state = //acquire or instantiate as necessary try { state.bind(); doSomething(); //execute any logic downstream logic that might need to access the state } finally { state.restore(); }
void clear()
ThreadContext
state. Typically this method should
only be called in special cases - it is more 'correct' to restore
a thread to its previous
state than to clear it entirely.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |