Package org.apache.ignite.internal.util
Class GridSpinBusyLock
- java.lang.Object
-
- org.apache.ignite.internal.util.GridSpinBusyLock
-
@GridToStringExclude public class GridSpinBusyLock extends Object
Synchronization aid to track "busy" state of a subsystem that owns it.Main difference over
GridBusyLockis that this class is implemented overGridSpinReadWriteLock.For example, there may be a manager that have different threads for some purposes and the manager must not be stopped while at least a single thread is in "busy" state. In this situation each thread must enter to "busy" state calling method
enterBusy()in critical pieces of code which, i.e. use grid kernal functionality, notifying that the manager and the whole grid kernal cannot be stopped while it's in progress. Once the activity is done, the thread should leave "busy" state calling methodleaveBusy(). The manager itself, when stopping, should call methodblock()that blocks till all activities leave "busy" state.- See Also:
GridBusyLock,GridSpinReadWriteLock
-
-
Constructor Summary
Constructors Constructor Description GridSpinBusyLock()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidblock()Blocks current thread till all activities left "busy" state and prevents them from further entering to "busy" state.booleanblockedByCurrentThread()Checks if busy lock was blocked by current thread.booleanenterBusy()Enters "busy" state.voidleaveBusy()Leaves "busy" state.booleantryBlock(long millis)voidunblock()Makes possible for activities entering busy state again.
-
-
-
Method Detail
-
enterBusy
public boolean enterBusy()
Enters "busy" state.- Returns:
trueif entered to busy state.
-
blockedByCurrentThread
public boolean blockedByCurrentThread()
Checks if busy lock was blocked by current thread.- Returns:
Trueif busy lock was blocked by current thread.
-
leaveBusy
public void leaveBusy()
Leaves "busy" state.
-
block
public void block()
Blocks current thread till all activities left "busy" state and prevents them from further entering to "busy" state.
-
tryBlock
public boolean tryBlock(long millis) throws InterruptedException- Parameters:
millis- Timeout.- Returns:
Trueif lock was acquired.- Throws:
InterruptedException- If interrupted.
-
unblock
public void unblock()
Makes possible for activities entering busy state again.
-
-