Package java.util.concurrent

Examples of java.util.concurrent.ForkJoinPool$ForkJoinWorkerThreadFactory


    this.asyncMode = asyncMode;
  }

  public void afterPropertiesSet() {
    this.forkJoinPool =
        new ForkJoinPool(this.parallelism, this.threadFactory, this.uncaughtExceptionHandler, this.asyncMode);
  }
View Full Code Here


    /**
     * Creates a {@code MergeSort} containing a ForkJoinPool with the indicated parallelism level
     * @param parallelism the parallelism level used
     */
    public MergeSort(int parallelism) {
        pool = new ForkJoinPool(parallelism);
    }
View Full Code Here

   * @throws InterruptedException
   * @throws ExecutionException
   */
  public static void main(String[] args) throws InterruptedException, ExecutionException {
   
    ForkJoinPool pool = new ForkJoinPool();
    Task executionTask = new Task(1000000000.0);
    pool.invoke(executionTask);
    System.out.println(pool.toString());
    System.out.println(String.format("Full execution time is %d", executionTask.get()));
    pool.shutdown();
  }
View Full Code Here

   
    // 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
    SearchNumberTask task=new SearchNumberTask(array,0,1000,5,manager);
   
    // Execute the task
    pool.execute(task);

    // Shutdown the pool
    pool.shutdown();
   
   
    // Wait for the finalization of the task
    try {
      pool.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
   
    // Write a message to indicate the end of the program
View Full Code Here

    }
    end=new Date();
    System.out.printf("Main: Executor: %d\n",(end.getTime()-start.getTime()));
   
    TaskFJ taskFJ=new TaskFJ(array,1,100000);
    ForkJoinPool pool=new ForkJoinPool();
    start=new Date();
    pool.execute(taskFJ);
    pool.shutdown();
    try {
      pool.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    end=new Date();
    System.out.printf("Core: Fork/Join: %d\n",(end.getTime()-start.getTime()));
View Full Code Here

   
    // Craete a task
    Task task=new Task(products, 0, products.size(), 0.20);
   
    // Create a ForkJoinPool
    ForkJoinPool pool=new ForkJoinPool();
   
    // Execute the Task
    pool.execute(task);

    // Write information about the pool
    do {
      System.out.printf("Main: Thread Count: %d\n",pool.getActiveThreadCount());
      System.out.printf("Main: Thread Steal: %d\n",pool.getStealCount());
      System.out.printf("Main: Paralelism: %d\n",pool.getParallelism());
      try {
        TimeUnit.MILLISECONDS.sleep(5);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    } while (!task.isDone());
 
    // Shutdown the pool
    pool.shutdown();
   
    // Check if the task has completed normally
    if (task.isCompletedNormally()){
      System.out.printf("Main: The process has completed normally.\n");
    }
View Full Code Here

    // 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);
 
    // Shutdown the pool
    pool.shutdown();
   
    // Wait for the finalization of the tasks
    try {
      pool.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
   
    System.out.printf("Main: The program has finished.\n");
View Full Code Here

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

    /*
     * Create the Fork/Join pool
     */
    ForkJoinPool pool=new ForkJoinPool();
   
    /*
     * Create a new Array of integer numbers with 10000 elements
     */
    int array[]=new int[10000];
   
    /*
     * Create a new task
     */
    Task task1=new Task(array,0,array.length);
   
    /*
     * Execute the task in the Fork/Join pool
     */
    pool.execute(task1);
   
    /*
     * Wait for the finalization of the task writing information
     * about the pool every second
     */
    while (!task1.isDone()) {
      showLog(pool);
      TimeUnit.SECONDS.sleep(1);
    }
   
    /*
     * Shutdown the pool
     */
    pool.shutdown();
   
    /*
     * Wait for the finalization of the pool
     */
    pool.awaitTermination(1, TimeUnit.DAYS);
   
    /*
     * End of the program
     */
    showLog(pool);
 
View Full Code Here

 
    // Create a DocumentTask
    DocumentTask task=new DocumentTask(document, 0, 100, "the");
   
    // Create a ForkJoinPool
    ForkJoinPool pool=new ForkJoinPool();
   
    // Execute the Task
    pool.execute(task);
   
    // Write statistics about the pool
    do {
      System.out.printf("******************************************\n");
      System.out.printf("Main: Parallelism: %d\n",pool.getParallelism());
      System.out.printf("Main: Active Threads: %d\n",pool.getActiveThreadCount());
      System.out.printf("Main: Task Count: %d\n",pool.getQueuedTaskCount());
      System.out.printf("Main: Steal Count: %d\n",pool.getStealCount());
      System.out.printf("******************************************\n");

      try {
        TimeUnit.SECONDS.sleep(1);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
     
    } while (!task.isDone());

    // Shutdown the pool
    pool.shutdown();
   
    // Wait for the finalization of the tasks
    try {
      pool.awaitTermination(1, TimeUnit.DAYS);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
   
    // Write the results of the tasks
View Full Code Here

    int array[]=new int[10000];
   
    /*
     * ForkJoinPool to execute the task
     */
    ForkJoinPool pool=new ForkJoinPool();
   
    /*
     * Task to increment the elements of the array
     */
    Task task=new Task("Task",array,0,array.length);
   
    /*
     * Send the task to the pool
     */
    pool.invoke(task);
   
    /*
     * Shutdown the pool
     */
    pool.shutdown();
   
    /*
     * Write a message in the console
     */
    System.out.printf("Main: End of the program.\n");
View Full Code Here

TOP

Related Classes of java.util.concurrent.ForkJoinPool$ForkJoinWorkerThreadFactory

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.