Sdílet prostřednictvím


CyclicBarrier.Await Method

Definition

Overloads

Await()

Waits until all #getParties parties have invoked await on this barrier.

Await(Int64, TimeUnit)

Waits until all #getParties parties have invoked await on this barrier, or the specified waiting time elapses.

Await()

Waits until all #getParties parties have invoked await on this barrier.

[Android.Runtime.Register("await", "()I", "GetAwaitHandler")]
public virtual int Await ();
[<Android.Runtime.Register("await", "()I", "GetAwaitHandler")>]
abstract member Await : unit -> int
override this.Await : unit -> int

Returns

the arrival index of the current thread, where index getParties() - 1 indicates the first to arrive and zero indicates the last to arrive

Attributes

Exceptions

if the current thread was interrupted while waiting

if another thread was interrupted or timed out while the current thread was waiting, or the barrier was reset, or the barrier was broken when await was called, or the barrier action (if present) failed due to an exception

Remarks

Waits until all #getParties parties have invoked await on this barrier.

If the current thread is not the last to arrive then it is disabled for thread scheduling purposes and lies dormant until one of the following things happens: <ul> <li>The last thread arrives; or <li>Some other thread Thread#interrupt interrupts the current thread; or <li>Some other thread Thread#interrupt interrupts one of the other waiting threads; or <li>Some other thread times out while waiting for barrier; or <li>Some other thread invokes #reset on this barrier. </ul>

If the current thread: <ul> <li>has its interrupted status set on entry to this method; or <li>is Thread#interrupt interrupted while waiting </ul> then InterruptedException is thrown and the current thread's interrupted status is cleared.

If the barrier is #reset while any thread is waiting, or if the barrier #isBroken is broken when await is invoked, or while any thread is waiting, then BrokenBarrierException is thrown.

If any thread is Thread#interrupt interrupted while waiting, then all other waiting threads will throw BrokenBarrierException and the barrier is placed in the broken state.

If the current thread is the last thread to arrive, and a non-null barrier action was supplied in the constructor, then the current thread runs the action before allowing the other threads to continue. If an exception occurs during the barrier action then that exception will be propagated in the current thread and the barrier is placed in the broken state.

Java documentation for java.util.concurrent.CyclicBarrier.await().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Await(Int64, TimeUnit)

Waits until all #getParties parties have invoked await on this barrier, or the specified waiting time elapses.

[Android.Runtime.Register("await", "(JLjava/util/concurrent/TimeUnit;)I", "GetAwait_JLjava_util_concurrent_TimeUnit_Handler")]
public virtual int Await (long timeout, Java.Util.Concurrent.TimeUnit? unit);
[<Android.Runtime.Register("await", "(JLjava/util/concurrent/TimeUnit;)I", "GetAwait_JLjava_util_concurrent_TimeUnit_Handler")>]
abstract member Await : int64 * Java.Util.Concurrent.TimeUnit -> int
override this.Await : int64 * Java.Util.Concurrent.TimeUnit -> int

Parameters

timeout
Int64

the time to wait for the barrier

unit
TimeUnit

the time unit of the timeout parameter

Returns

the arrival index of the current thread, where index getParties() - 1 indicates the first to arrive and zero indicates the last to arrive

Attributes

Exceptions

if the current thread was interrupted while waiting

if the specified timeout elapses

if another thread was interrupted or timed out while the current thread was waiting, or the barrier was reset, or the barrier was broken when await was called, or the barrier action (if present) failed due to an exception

Remarks

Waits until all #getParties parties have invoked await on this barrier, or the specified waiting time elapses.

If the current thread is not the last to arrive then it is disabled for thread scheduling purposes and lies dormant until one of the following things happens: <ul> <li>The last thread arrives; or <li>The specified timeout elapses; or <li>Some other thread Thread#interrupt interrupts the current thread; or <li>Some other thread Thread#interrupt interrupts one of the other waiting threads; or <li>Some other thread times out while waiting for barrier; or <li>Some other thread invokes #reset on this barrier. </ul>

If the current thread: <ul> <li>has its interrupted status set on entry to this method; or <li>is Thread#interrupt interrupted while waiting </ul> then InterruptedException is thrown and the current thread's interrupted status is cleared.

If the specified waiting time elapses then TimeoutException is thrown. If the time is less than or equal to zero, the method will not wait at all.

If the barrier is #reset while any thread is waiting, or if the barrier #isBroken is broken when await is invoked, or while any thread is waiting, then BrokenBarrierException is thrown.

If any thread is Thread#interrupt interrupted while waiting, then all other waiting threads will throw BrokenBarrierException and the barrier is placed in the broken state.

If the current thread is the last thread to arrive, and a non-null barrier action was supplied in the constructor, then the current thread runs the action before allowing the other threads to continue. If an exception occurs during the barrier action then that exception will be propagated in the current thread and the barrier is placed in the broken state.

Java documentation for java.util.concurrent.CyclicBarrier.await(long, java.util.concurrent.TimeUnit).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to