Package com.packtpub.java7.concurrency.chapter1.recipe1.task

Examples of com.packtpub.java7.concurrency.chapter1.recipe1.task.Calculator


   
    // Create a ForkJoinPool with the default constructor
    ForkJoinPool pool=new ForkJoinPool();
   
    // Create a Task to process the array
    SearchNumberTask task=new SearchNumberTask(array,0,1000,5,manager);
   
    // Execute the task
    pool.execute(task);

    // Shutdown the pool
View Full Code Here


   * @param args
   */
  public static void main(String[] args) {

    // Generate an array of 1000 integers
    ArrayGenerator generator=new ArrayGenerator();
    int array[]=generator.generateArray(1000);
   
    // Create a TaskManager object
    TaskManager manager=new TaskManager();
   
    // Create a ForkJoinPool with the default constructor
View Full Code Here

    // Generate an array of 1000 integers
    ArrayGenerator generator=new ArrayGenerator();
    int array[]=generator.generateArray(1000);
   
    // Create a TaskManager object
    TaskManager manager=new TaskManager();
   
    // Create a ForkJoinPool with the default constructor
    ForkJoinPool pool=new ForkJoinPool();
   
    // Create a Task to process the array
View Full Code Here

    OneSecondLongTask task=new OneSecondLongTask();
   
    // Creates a new Handler
    Handler handler = new Handler();
    // Creates a Factory
    AlwaysThrowsExceptionWorkerThreadFactory factory=new AlwaysThrowsExceptionWorkerThreadFactory();
    // Creates a new ForkJoinPool
    ForkJoinPool pool=new ForkJoinPool(2,factory,handler,false);
   
    // Execute the task in the pool
    pool.execute(task);
View Full Code Here

    // Creates a task
    OneSecondLongTask task=new OneSecondLongTask();
   
    // Creates a new Handler
    Handler handler = new Handler();
    // Creates a Factory
    AlwaysThrowsExceptionWorkerThreadFactory factory=new AlwaysThrowsExceptionWorkerThreadFactory();
    // Creates a new ForkJoinPool
    ForkJoinPool pool=new ForkJoinPool(2,factory,handler,false);
   
View Full Code Here

   * @param args
   */
  public static void main(String[] args) {

    // Creates a task
    OneSecondLongTask task=new OneSecondLongTask();
   
    // Creates a new Handler
    Handler handler = new Handler();
    // Creates a Factory
    AlwaysThrowsExceptionWorkerThreadFactory factory=new AlwaysThrowsExceptionWorkerThreadFactory();
View Full Code Here

  public static void main(String[] args) throws Exception {

    // Create a ConcurrentLinkedDeque to work with it in the example
    LinkedBlockingDeque<String> list=new LinkedBlockingDeque<>(3);
   
    Client client=new Client(list);
    Thread thread=new Thread(client);
    thread.start();
   
    for (int i=0; i<5 ; i++) {
      for (int j=0; j<3; j++) {
View Full Code Here

   
    /*
     * Launch 100 Consumer tasks
     */
    for (int i=0; i<THREADS; i++){
      Consumer consumer=new Consumer("Consumer "+i,buffer);
      consumerThreads[i]=new Thread(consumer);
      consumerThreads[i].start();
    }
   
    /*
 
View Full Code Here

   
    /*
     * Launch 100 Producer tasks
     */
    for (int i=0; i<THREADS; i++) {
      Producer producer=new Producer("Producer: "+i,buffer);
      producerThreads[i]=new Thread(producer);
      producerThreads[i].start();
    }
   
    /*
 
View Full Code Here

    /*
     * Write the events in the console
     */
    System.out.printf("Main: Queue Size: %d\n",queue.size());
    for (int i=0; i<taskThreads.length*1000; i++){
      Event event=queue.poll();
      System.out.printf("Thread %s: Priority %d\n",event.getThread(),event.getPriority());
    }
    System.out.printf("Main: Queue Size: %d\n",queue.size());
    System.out.printf("Main: End of the program\n");
  }
View Full Code Here

TOP

Related Classes of com.packtpub.java7.concurrency.chapter1.recipe1.task.Calculator

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.