Java Phaser awaitAdvanceInterruptibly() Method

The awaitAdvanceInterruptibly() method is of Phaser class. Using this method, the phase can await the current phaser from the given phaser value.

Syntax

Parameters

Phase: current phaser value

Return

It returns number of the next arrived phaser.

Throws

InterruptedException - it throws exception if a thread interrupts while it is waiting.

Example 1

Test it Now

Output:

Thread is sleeping
Thread-0 arrived
Thread-4 arrived
Thread-2 arrived
Thread-3 arrived
Thread-5 arrived
Thread-1 arrived

Example 2

Test it Now

Output:

Thread is sleeping
Thread-0 arrived
Thread-1 arrived

Java Phaser awaitAdvanceInterruptibly(int phase, long timeout, TimeUnit unit)

The awaitAdvanceInterruptibly() method of Phaser class awaits the phase of this phaser to advance from the given timeout to elapse or the given phase value.

Syntax

Parameters

phase - It is an arrival phase number

timeout - waiting time

unit - It is a TimeUnit for determining how to interpret the timeout parameter

Returns

It returns the phase number of next arrival. If it is negative, then returns the arguments

Throws

InterruptedException - It throws an exception if thread interrupted while

waitingTimeoutException - It throws an exception if timed out while waiting

Example 3

Test it Now

Output:

Thread is sleeping
Thread-0 arrived
Thread-4 arrived
Thread-2 arrived
Thread-3 arrived
Thread-5 arrived
Thread-1 arrived

Example 4

Test it Now

Output:

Thread is sleeping
Thread-0 arrived
Thread-1 arrived

Next TopicJava Phaser




Latest Courses