Example usage for java.util.concurrent Phaser forceTermination

List of usage examples for java.util.concurrent Phaser forceTermination

Introduction

In this page you can find the example usage for java.util.concurrent Phaser forceTermination.

Prototype

public void forceTermination() 

Source Link

Document

Forces this phaser to enter termination state.

Usage

From source file:Main.java

public static void main(String[] args) {
    Phaser phaser = new Phaser() {
        protected boolean onAdvance(int phase, int parties) {
            System.out.println("Inside onAdvance(): phase  = " + phase + ",  Registered Parties = " + parties);
            // Do not terminate the phaser by returning false
            return false;
        }/*from   w w  w  .  jav  a2  s  .  co  m*/
    };
    // Register the self (the "main" thread) as a party 
    phaser.register();
    System.out.println("#1: isTerminated():" + phaser.isTerminated());
    phaser.arriveAndDeregister();

    // Trigger another phase advance
    phaser.register();
    phaser.arriveAndDeregister();

    System.out.println("#2: isTerminated():" + phaser.isTerminated());
    phaser.forceTermination();
    System.out.println("#3: isTerminated():" + phaser.isTerminated());
}