Examples of MyPhaser


Examples of com.packtpub.java7.concurrency.chapter3.recipe6.task.MyPhaser

   * @param args
   */
  public static void main(String[] args) {
   
    // Creates the Phaser
    MyPhaser phaser=new MyPhaser();
   
    // Creates 5 students and register them in the phaser
    Student students[]=new Student[5];
    for (int i=0; i<students.length; i++){
      students[i]=new Student(phaser);
      phaser.register();
    }
   
    // Create 5 threads for the students and start them
    Thread threads[]=new Thread[students.length];
    for (int i=0; i<students.length; i++) {
      threads[i]=new Thread(students[i],"Student "+i);
      threads[i].start();
    }
   
    // Wait for the finalization of the threads
    for (int i=0; i<threads.length; i++) {
      try {
        threads[i].join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
   
    // Check that the Phaser is in the Terminated state
    System.out.printf("Main: The phaser has finished: %s.\n",phaser.isTerminated());
   
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.