|
Liferay 6.0.5 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.liferay.portal.kernel.concurrent.CompeteLatch
public class CompeteLatch
A synchronizer based on the JDK's AQS framework to simulate a single winner
competition. This synchronizer supports cyclical competition. In this
situation, loser threads should try again. The single winner thread will lock
the latch while other threads will block on the latch by calling
await
. After the winner thread finishes its job, it should call
done
which will open the latch. All blocking loser threads can
pass the latch at the same time.
See LPS-3744 for a sample use case.
Constructor Summary | |
---|---|
CompeteLatch()
|
Method Summary | |
---|---|
void |
await()
This method should only be called by a loser thread. |
boolean |
await(long timeout,
TimeUnit timeUnit)
This method should only be called by a loser thread. |
boolean |
compete()
Tells the current thread to join the competition. |
boolean |
done()
This method should only be called by the winner thread. |
boolean |
isLocked()
Returns true if the latch is locked. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CompeteLatch()
Method Detail |
---|
public void await() throws InterruptedException
InterruptedException
- if the current thread is interruptedpublic boolean await(long timeout, TimeUnit timeUnit) throws InterruptedException
InterruptedException
- if the current thread is interruptedpublic boolean compete()
true
if the current thread is the winner threadpublic boolean done()
await
method. If a loser thread does call this method when a winner thread has
locked the latch, the latch will break and the winner thread may be put
into a non thread safe state. You should never have to do this except to
get out of a deadlock. If no one threads have locked the latch, then
calling this method has no effect. This method will return immediately.
false
if the
latch is already openpublic boolean isLocked()
true
if the latch is locked. This method should not
be used to test the latch before joining a competition because it is not
thread safe. The only purpose for this method is to give external systems
a way to monitor the latch which is usually be used for deadlock
detection.
|
Liferay 6.0.5 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |