Package com.packtpub.java7.concurrency.chapter4.recipe6.task

Examples of com.packtpub.java7.concurrency.chapter4.recipe6.task.Result


    Thread threadProducer=new Thread(producer,"Producer");
   
    /**
     * Creates three consumers and threads to run them
     */
    Consumer consumers[]=new Consumer[3];
    Thread threadConsumers[]=new Thread[3];
   
    for (int i=0; i<3; i++){
      consumers[i]=new Consumer(buffer);
      threadConsumers[i]=new Thread(consumers[i],"Consumer "+i);
    }
   
    /**
     * Strats the producer and the consumers
View Full Code Here


    Buffer buffer=new Buffer(20);
   
    /**
     * Creates a producer and a thread to run it
     */
    Producer producer=new Producer(mock, buffer);
    Thread threadProducer=new Thread(producer,"Producer");
   
    /**
     * Creates three consumers and threads to run them
     */
 
View Full Code Here

   */
  public static void main(String[] args) {
    /**
     * Creates a simulated file with 100 lines
     */
    FileMock mock=new FileMock(101, 10);
   
    /**
     * Creates a buffer with a maximum of 20 lines
     */
    Buffer buffer=new Buffer(20);
View Full Code Here

    PrintQueue printQueue=new PrintQueue();
   
    // Creates ten Threads
    Thread thread[]=new Thread[10];
    for (int i=0; i<10; i++){
      thread[i]=new Thread(new Job(printQueue),"Thread "+i);
    }
   
    // Starts the Threads
    for (int i=0; i<10; i++){
      thread[i].start();
View Full Code Here

   * send documents to the print queue at the same time.
   */
  public static void main (String args[]){
   
    // Creates the print queue
    PrintQueue printQueue=new PrintQueue();
   
    // Creates ten Threads
    Thread thread[]=new Thread[10];
    for (int i=0; i<10; i++){
      thread[i]=new Thread(new Job(printQueue),"Thread "+i);
View Full Code Here

   
    // Initializes the object for the results
    Results results=new Results(ROWS);
   
    // Creates an Grouper object
    Grouper grouper=new Grouper(results);
   
    // Creates the CyclicBarrier object. It has 5 participants and, when
    // they finish, the CyclicBarrier will execute the grouper object
    CyclicBarrier barrier=new CyclicBarrier(PARTICIPANTS,grouper);
   
View Full Code Here

    // Creates the CyclicBarrier object. It has 5 participants and, when
    // they finish, the CyclicBarrier will execute the grouper object
    CyclicBarrier barrier=new CyclicBarrier(PARTICIPANTS,grouper);
   
    // Creates, initializes and starts 5 Searcher objects
    Searcher searchers[]=new Searcher[PARTICIPANTS];
    for (int i=0; i<PARTICIPANTS; i++){
      searchers[i]=new Searcher(i*LINES_PARTICIPANT, (i*LINES_PARTICIPANT)+LINES_PARTICIPANT, mock, results, 5,barrier);
      Thread thread=new Thread(searchers[i]);
      thread.start();
    }
    System.out.printf("Main: The main thread has finished.\n");
  }
View Full Code Here

    final int ROWS=10000;
    final int NUMBERS=1000;
    final int SEARCH=5;
    final int PARTICIPANTS=5;
    final int LINES_PARTICIPANT=2000;
    MatrixMock mock=new MatrixMock(ROWS, NUMBERS,SEARCH);
   
    // Initializes the object for the results
    Results results=new Results(ROWS);
   
    // Creates an Grouper object
View Full Code Here

    final int PARTICIPANTS=5;
    final int LINES_PARTICIPANT=2000;
    MatrixMock mock=new MatrixMock(ROWS, NUMBERS,SEARCH);
   
    // Initializes the object for the results
    Results results=new Results(ROWS);
   
    // Creates an Grouper object
    Grouper grouper=new Grouper(results);
   
    // Creates the CyclicBarrier object. It has 5 participants and, when
View Full Code Here

   * @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

Related Classes of com.packtpub.java7.concurrency.chapter4.recipe6.task.Result

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.