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

Examples of com.packtpub.java7.concurrency.chapter3.recipe2.task.Job


   */
  public static void main(String[] args) {
    // Array of 100 integers
    int array[]=new int[100];
    // Task to process the array
    Task task=new Task(array,0,100);
    // ForkJoinPool to execute the Task
    ForkJoinPool pool=new ForkJoinPool();
   
    // Execute the task
    pool.execute(task);
 
    // Shutdown the ForkJoinPool
    pool.shutdown();
   
    // Wait for the finalization of the task
    try {
      pool.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
   
    // Check if the task has thrown an Exception. If it's the case, write it
    // to the console
   
    if (task.isCompletedAbnormally()) {
      System.out.printf("Main: An exception has ocurred\n");
      System.out.printf("Main: %s\n",task.getException());
    }
   
    System.out.printf("Main: Result: %d",task.join());
  }
View Full Code Here


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

TOP

Related Classes of com.packtpub.java7.concurrency.chapter3.recipe2.task.Job

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.