Package com.packtpub.java7.concurrency.chapter2.recipe2.core

Examples of com.packtpub.java7.concurrency.chapter2.recipe2.core.Main


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

    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

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

    ExecutorService executor=(ExecutorService)Executors.newCachedThreadPool();
   
    //Create five tasks
    ResultTask resultTasks[]=new ResultTask[5];
    for (int i=0; i<5; i++) {
      ExecutableTask executableTask=new ExecutableTask("Task "+i);
      resultTasks[i]=new ResultTask(executableTask);
      executor.submit(resultTasks[i]);
    }
   
    // Sleep the thread five seconds
View Full Code Here

  public static void main(String[] args) {
    // Create an executor
    ExecutorService executor=(ExecutorService)Executors.newCachedThreadPool();
   
    //Create five tasks
    ResultTask resultTasks[]=new ResultTask[5];
    for (int i=0; i<5; i++) {
      ExecutableTask executableTask=new ExecutableTask("Task "+i);
      resultTasks[i]=new ResultTask(executableTask);
      executor.submit(resultTasks[i]);
    }
   
    // Sleep the thread five seconds
    try {
View Full Code Here

    ReportRequest onlineRequest=new ReportRequest("Online", service);
    Thread faceThread=new Thread(faceRequest);
    Thread onlineThread=new Thread(onlineRequest);
   
    // Create a ReportSender object and a Thread to execute  it
    ReportProcessor processor=new ReportProcessor(service);
    Thread senderThread=new Thread(processor);
   
    // Start the Threads
    System.out.printf("Main: Starting the Threads\n");
    faceThread.start();
    onlineThread.start();
    senderThread.start();
   
    // Wait for the end of the ReportGenerator tasks
    try {
      System.out.printf("Main: Waiting for the report generators.\n");
      faceThread.join();
      onlineThread.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
   
    // Shutdown the executor
    System.out.printf("Main: Shuting down the executor.\n");
    executor.shutdown();
    try {
      executor.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    // End the execution of the ReportSender
    processor.setEnd(true);
    System.out.printf("Main: Ends\n");

  }
View Full Code Here

TOP

Related Classes of com.packtpub.java7.concurrency.chapter2.recipe2.core.Main

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.