Package java.util.concurrent

Examples of java.util.concurrent.Phaser


  /**
   * @param args
   */
  public static void main(String[] args) {
    byte threadNumber = 2;
    Phaser phaser = new Phaser();
    for (byte i = 1; i <= threadNumber; i++)
      new Thread(new PhasedTask(phaser, i)).start();
   
  }
View Full Code Here


   * @param args
   */
  public static void main(String[] args) {
   
    // Creates a Phaser with three participants
    Phaser phaser=new Phaser(3);
   
    // Creates 3 FileSearch objects. Each of them search in different directory
    FileSearch system=new FileSearch("C:\\Windows", "log", phaser);
    FileSearch apps=new FileSearch("C:\\Program Files","log",phaser);
    FileSearch documents=new FileSearch("C:\\Documents And Settings","log",phaser);
   
    // Creates a thread to run the system FileSearch and starts it
    Thread systemThread=new Thread(system,"System");
    systemThread.start();
   
    // Creates a thread to run the apps FileSearch and starts it
    Thread appsThread=new Thread(apps,"Apps");
    appsThread.start();
   
    // Creates a thread to run the documents  FileSearch and starts it
    Thread documentsThread=new Thread(documents,"Documents");
    documentsThread.start();
    try {
      systemThread.join();
      appsThread.join();
      documentsThread.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
   
    System.out.printf("Terminated: %s\n",phaser.isTerminated());

  }
View Full Code Here

   */
  public static void main(String[] args) throws Exception {
    /*
     * Create a new Phaser for three participants
     */
    Phaser phaser=new Phaser(3);
   
    /*
     * Create and launch three tasks
     */
    for (int i=0; i<3; i++) {
      Task task=new Task(i+1, phaser);
      Thread thread=new Thread(task);
      thread.start();
    }
   
    /*
     * Write information about the Phaser
     */
    for (int i=0; i<10; i++) {
      System.out.printf("********************\n");
      System.out.printf("Main: Phaser Log\n");
      System.out.printf("Main: Phaser: Phase: %d\n",phaser.getPhase());
      System.out.printf("Main: Phaser: Registered Parties: %d\n",phaser.getRegisteredParties());
      System.out.printf("Main: Phaser: Arrived Parties: %d\n",phaser.getArrivedParties());
      System.out.printf("Main: Phaser: Unarrived Parties: %d\n",phaser.getUnarrivedParties());
      System.out.printf("********************\n");

      TimeUnit.SECONDS.sleep(1);
    }
  }
 
View Full Code Here

   */
  @Test
  public void illegalStateClearBlocked1() throws ParserException {
    initAvoidance();
    // we do not use the Byteman integration    
    final Phaser a = new pt.ul.jarmus.ext.Phaser(1);
    final Phaser b = new pt.ul.jarmus.ext.Phaser(1);
    JArmus.register(a);
    JArmus.register(b);
    b.arriveAndAwaitAdvance();
    a.arriveAndAwaitAdvance();
  }
View Full Code Here

   */
  @Test
  public void illegalStateClearBlocked2() throws ParserException {
    initAvoidance();
       
    final Phaser a = new Phaser(1);
    final Phaser b = new Phaser(1);
    JArmus.register(a);
    JArmus.register(b);
    b.arriveAndAwaitAdvance();
    a.arriveAndAwaitAdvance();
  }
View Full Code Here

   */
  @Test
  public void falseDeadlock1a() {
    initAvoidance();
       
    final Phaser a = new pt.ul.jarmus.ext.Phaser(1);
    final Phaser b = new pt.ul.jarmus.ext.Phaser(1);
    JArmus.register(a);
    JArmus.register(b);
    b.arrive();
    a.arriveAndAwaitAdvance();
    b.awaitAdvance(0);
  }
View Full Code Here

   */
  @Test
  public void falseDeadlock1b() throws InterruptedException, InstantiationException, IllegalAccessException {
    initAvoidance();
       
    final Phaser a = new Phaser(1);
    final Phaser b = new Phaser(1);
    JArmus.register(a);
    JArmus.register(b);
    b.arrive();
    a.arriveAndAwaitAdvance();
    b.awaitAdvance(0);
  }
View Full Code Here

   */
  @Test
  public void falseDeadlock1c() throws InterruptedException, InstantiationException, IllegalAccessException {
    initAvoidance();
       
    final Phaser a = new Phaser(1);
    final Phaser b = new Phaser(1);
    JArmus.register(a);
    JArmus.register(b);

    PhaserChecker ph = new PhaserChecker();
    ph.onArrive(b);
View Full Code Here

  public void falseDeadlock1d() throws InterruptedException, InstantiationException, IllegalAccessException {
    PhaserListener facade = Mockito.mock(PhaserListener.class);
    PhaserObserver.aspectOf().setListener(facade);
    initAvoidance();
   
    final Phaser a = new Phaser(1);
    final Phaser b = new Phaser(1);
    JArmus.register(a);
    JArmus.register(b);
    b.arrive();
    a.arriveAndAwaitAdvance();
    b.awaitAdvance(0);
   
   
    // Verify phase
    InOrder inOrder = inOrder(facade);
    inOrder.verify(facade).onArrive(b);
View Full Code Here

   */
  @Test
  public void forgotToSetBlocked() throws InstantiationException, IllegalAccessException {
    initAvoidance();
   
    final Phaser barrier1 = new Phaser(1);
    JArmus.register(barrier1);
    assertTrue(JArmus.getSetup().getController().isRegistered(barrier1));
    try {
      barrier1.awaitAdvance(0);
    } catch (DeadlockIdentifiedException e) {
      // ok
    }
  }
View Full Code Here

TOP

Related Classes of java.util.concurrent.Phaser

Copyright © 2018 www.massapicom. 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.