Package com.packtpub.java7.concurrency.chapter3.recipe7.task

Examples of com.packtpub.java7.concurrency.chapter3.recipe7.task.Producer


   
    // 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

   
    // 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();
   
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

   
    // 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];
View Full Code Here

    Exchanger<List<String>> exchanger=new Exchanger<>();
   
    // Creates the producer
    Producer producer=new Producer(buffer1, exchanger);
    // Creates the consumer
    Consumer consumer=new Consumer(buffer2, exchanger);
   
    // Creates and starts the threads
    Thread threadProducer=new Thread(producer);
    Thread threadConsumer=new Thread(consumer);
   
View Full Code Here

   
    // Creates the exchanger
    Exchanger<List<String>> exchanger=new Exchanger<>();
   
    // Creates the producer
    Producer producer=new Producer(buffer1, exchanger);
    // Creates the consumer
    Consumer consumer=new Consumer(buffer2, exchanger);
   
    // Creates and starts the threads
    Thread threadProducer=new Thread(producer);
View Full Code Here

   * Main method of the example
   * @param args
   */
  public static void main(String[] args) {
    // Create the server
    Server server=new Server();
   
    // Send 100 request to the server and finish
    for (int i=0; i<100; i++){
      Task task=new Task("Task "+i);
      server.executeTask(task);
    }
   
    server.endServer();

  }
View Full Code Here

TOP

Related Classes of com.packtpub.java7.concurrency.chapter3.recipe7.task.Producer

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.