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

Examples of com.packtpub.java7.concurrency.chapter4.recipe7.task.Task


    Account  account=new Account();
    // an initialize its balance to 1000
    account.setBalance(1000);
   
    // Creates a new Company and a Thread to run its task
    Company  company=new Company(account);
    Thread companyThread=new Thread(company);
    // Creates a new Bank and a Thread to run its task
    Bank bank=new Bank(account);
    Thread bankThread=new Thread(bank);
   
View Full Code Here


   * @param args
   */
  public static void main(String[] args) {
   
    // Create a new object for the statistics
    BuildStats stats=new BuildStats();

    // Create a Sensor1 object and a Thread to run it
    Sensor1 sensor1=new Sensor1(stats);
    Thread thread1=new Thread(sensor1,"Sensor 1");

    // Create a Sensor 2 object and a Thread to run it
    Sensor2 sensor2=new Sensor2(stats);
    Thread thread2=new Thread(sensor2,"Sensor 2");
   
    // Get the actual time
    Date date1=new Date();
   
    //Starts the threads
    thread1.start();
    thread2.start();
   
    try {
      // Wait for the finalization of the threads
      thread1.join();
      thread2.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    //Get the actual time and print the execution time
    Date date2=new Date();
    stats.printStats();
    System.out.println("Execution Time: "+((date2.getTime()-date1.getTime())/1000));

  }
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

    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

TOP

Related Classes of com.packtpub.java7.concurrency.chapter4.recipe7.task.Task

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.