java.util.concurrent.CountDownLatch to allow counting up as well
as down.
| Modifier and Type | Class and Description |
|---|---|
| private static class | CountUpDownLatch.
Synchronization control For |
| Modifier and Type | Field and Description |
|---|---|
| private final CountUpDownLatch. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | CountUpDownLatch(int
the initial initialCount)countConstructs a new |
| Modifier and Type | Method and Description |
|---|---|
| public void | await()
Causes the current thread to wait until |
| public boolean | Returns: true if the count reached zero and false if the
waiting time elapsed before the count reached zerothe maximum time to wait timeout, TimeUnit the time unit of the unit)timeout argumentCauses the current thread to wait until |
| public boolean | Returns: true if count transitions to zeroDecrements the count of the latch, releasing all waiting threads if the count transitions to zero. |
| public boolean | Returns: true if count transitions to zeroby which to decrement the amount)countDecrements the |
| public boolean | Returns: true if count transitioned from zero to a new
valueIncrements the count of the latch. |
| public boolean | Returns: true if count transitioned from zero to a new
valueby which to increment amount)countIncrements the count of the latch by the given |
| public boolean | Returns: if and only ifthis == objto test. other)Returns true if and only if |
| public boolean | Returns: if and only ifthis == objto test. obj)Overrides java. Returns true if and only if |
| public int | |
| public int | Returns: a hash code value for this latch. This method is supported for the benefit of hash tablesOverrides java. As much as is reasonably practical, returns distinct integers for distinct objects. |
| public boolean | Returns: true if count transitions to zero.to which to update newCount)count; must be non-negative.Updates |
| public String | Returns: a string identifying this latch, as well as its currentcount.Overrides java. Returns a string representation of this object. |
| sync | back to summary |
|---|---|
| private final CountUpDownLatch. | |
| CountUpDownLatch | back to summary |
|---|---|
| public CountUpDownLatch() Default constructor.
Equivalent to | |
| CountUpDownLatch | back to summary |
|---|---|
| public CountUpDownLatch(int initialCount) Constructs a new
| |
| await | back to summary |
|---|---|
| public void await() throws InterruptedException Causes the current thread to wait until
If the current
If the current
InterruptedException is thrown and the current thread's
interrupted status is cleared.
| |
| await | back to summary |
|---|---|
| public boolean await(long timeout, TimeUnit unit) throws InterruptedException Causes the current thread to wait until
If the current
If the current
true.
If the current thread:
InterruptedException is thrown and the current thread's
interrupted status is cleared.
If the specified waiting time elapses then the value
| |
| countDown | back to summary |
|---|---|
| public boolean countDown() Decrements the count of the latch, releasing all waiting threads if the count transitions to zero. If the current count is zero, no action occurs and false is returned immediately;
| |
| countDown | back to summary |
|---|---|
| public boolean countDown(int amount) Decrements the
If the current
| |
| countUp | back to summary |
|---|---|
| public boolean countUp() Increments the count of the latch.
| |
| countUp | back to summary |
|---|---|
| public boolean countUp(int amount) Increments the count of the latch by the given
| |
| equals | back to summary |
|---|---|
| public boolean equals(final CountUpDownLatch other) Returns true if and only if
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Returns true if and only if
| |
| getCount | back to summary |
|---|---|
| public int getCount() Returns the current count.
Because another thread may update
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. As much as is reasonably practical, returns distinct integers for distinct objects.
| |
| setCount | back to summary |
|---|---|
| public boolean setCount(int newCount) Updates
If
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this object.
| |
CountUpDownLatch.
Uses AbstractQueuedSynchronizer state property to
represent count.
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv boolean | |
| pack-priv boolean | Returns: true if {#code count} transitioned to zero.by which to decrement the amount)countCounts down by |
| pack-priv boolean | |
| pack-priv boolean | Returns: true if count transitioned from zero to a new valueby which to increment amount)countCounts up by |
| pack-priv int | |
| pack-priv boolean | Returns: true if count transitions to zero.to which to update newCount)count; must be
non-negative.Updates |
| protected int | Returns: -1 on failure; 1 if acquisition in shared mode succeeded and subsequent shared-mode acquires might also succeed, in which case a subsequent waiting thread must check availability.ignored param ignored)Overrides java. Queries if the state of this synchronizer permits it to be acquired in the shared mode, and if so to acquire it. |
| protected boolean | tryReleaseShared(int arg)
Overrides java. Attempts to set the state to reflect a release in shared mode. |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. | |
| Sync | back to summary |
|---|---|
| pack-priv Sync(int count) | |
| countDown | back to summary |
|---|---|
| pack-priv boolean countDown() by one.
| |
| countDown | back to summary |
|---|---|
| pack-priv boolean countDown(int amount) Counts down by
| |
| countUp | back to summary |
|---|---|
| pack-priv boolean countUp() Counts up by one.
| |
| countUp | back to summary |
|---|---|
| pack-priv boolean countUp(int amount) Counts up by
| |
| getCount | back to summary |
|---|---|
| pack-priv int getCount() | |
| setCount | back to summary |
|---|---|
| pack-priv boolean setCount(int newCount) Updates
If
| |
| tryAcquireShared | back to summary |
|---|---|
| protected int tryAcquireShared(int ignored) Overrides java. Queries if the state of this synchronizer permits it to be acquired in the shared mode, and if so to acquire it.
This implementation supports the required semantics of the
| |
| tryReleaseShared | back to summary |
|---|---|
| protected boolean tryReleaseShared(int arg) Overrides java. Doc from java. Attempts to set the state to reflect a release in shared mode. This method is always invoked by the thread performing release. The default implementation throws
| |