public final class CriticalSectionManager
extends java.lang.Object
The class provides these methods:
beginSection()
and endSection()
must bracket any
portion of code which is determined to be sensitive to thread
interruption. Also, the endSection()
method ensures that,
when the critical section ends, it will force the interrupt flag
of the thread to be set if it was set when the critical section
started OR if an interruption occurred during the critical section
(which was deferred).
interrupt(java.lang.Thread)
is used to deliver an interruption to the
Conversation thread. This ensures that the interrupt will never bes
executed while a critical section is in process (in such a case the
interrupt is remembered but its application is deferred until the
endSection()
finds that all nested critical sections have
been exited). If no critical section is in process, the interrupt
is immediately applied to the given thread.
Modifier and Type | Class and Description |
---|---|
private static class |
CriticalSectionManager.WorkArea
Container for context-local variables.
|
Modifier and Type | Field and Description |
---|---|
private static ContextLocal<CriticalSectionManager.WorkArea> |
instance
Store context-local state variables.
|
Modifier | Constructor and Description |
---|---|
private |
CriticalSectionManager()
Private constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
beginSection()
Method called before the start of a critical section.
|
static void |
endSection()
Method called right after the end of a critical section; must be
executed in a
finally block. |
static void |
interrupt(java.lang.Thread thread)
Notify the target thread about an interruption.
|
private static final ContextLocal<CriticalSectionManager.WorkArea> instance
private CriticalSectionManager()
public static void beginSection()
When the lock was released, it will mark the start of a new critical section and also save the the interrupted state of the current thread.
public static void endSection()
finally
block.
This will decrement the critical section count and it will force the interrupt flag of the thread to be set if it was set when the critical section started OR if an interruption occurred during the critical section (if there is a deferred interrupt needing to be delivered).
public static void interrupt(java.lang.Thread thread)
thread
- The target thread which should be interrupted.