Package jsr166y

Examples of jsr166y.ForkJoinPool$EmptyTask


  @SuppressWarnings("boxing")
  public static void main(String[] args) throws Exception {
    String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    /* Create and configure a task pool manager (task executor) */
    ForkJoinPool taskExecutor = new ForkJoinPool();
    // Indicate to the task executor to use all processor of the current
    // machine
    taskExecutor.setParallelism(Runtime.getRuntime().availableProcessors());
    // In this sample tasks used here do not joined the we can disable the
    // AsyncMode (documentation
    // extract :
    // Establishes local first-in-first-out scheduling mode for forked tasks
    // that are never joined. This mode may be more appropriate than default
    // locally stack-based mode in applications in which worker threads only
    // process asynchronous tasks. This method is designed to be invoked
    // only when the pool is quiescent, and typically only before any tasks
    // are submitted. The effects of invocations at other times may be
    // unpredictable.)
    taskExecutor.setAsyncMode(false);
    // Indicate to the task executor to maintain parallelism
    taskExecutor.setMaintainsParallelism(true);

    /* Create a Phaser */
    Phaser phaser = new Phaser(alphabet.length());

    /* Create tasks */
    List<FileCounterRecursiveTaskWithPhaser> tasks = new ArrayList<FileCounterRecursiveTaskWithPhaser>(alphabet.length());
    for (char c : alphabet.toCharArray()) {
      tasks.add(new FileCounterRecursiveTaskWithPhaser(new File(c + ":\\"), phaser));
    }

    /* Launch tasks */
    for (FileCounterRecursiveTaskWithPhaser task : tasks) {
      taskExecutor.execute(task);
    }

    /*
     * Wait tasks termination using the Phaser and then display processing
     * state
 
View Full Code Here


   *        Command line
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    /* Create and configure a task pool manager (task executor) */
    ForkJoinPool taskExecutor = new ForkJoinPool();
    // Indicate to the task executor to use all processor of the current
    // machine
    taskExecutor.setParallelism(Runtime.getRuntime().availableProcessors());
    // In this sample tasks used here do not joined the we can disable the
    // AsyncMode (documentation
    // extract :
    // Establishes local first-in-first-out scheduling mode for forked tasks
    // that are never joined. This mode may be more appropriate than default
    // locally stack-based mode in applications in which worker threads only
    // process asynchronous tasks. This method is designed to be invoked
    // only when the pool is quiescent, and typically only before any tasks
    // are submitted. The effects of invocations at other times may be
    // unpredictable.)
    taskExecutor.setAsyncMode(false);
    // Indicate to the task executor to maintain parallelism
    taskExecutor.setMaintainsParallelism(true);

    /* Create and launch tasks with the task executor */
    FileCounterRecursiveTask task01 = new FileCounterRecursiveTask(new File("C:\\"));
    FileCounterRecursiveTask task02 = new FileCounterRecursiveTask(new File("D:\\"));
    FileCounterRecursiveTask task03 = new FileCounterRecursiveTask(new File("E:\\"));
    // Explicit invalid path in order that the task fail !
    FileCounterRecursiveTask task04 = new FileCounterRecursiveTask(new File("A:\\"));
    taskExecutor.execute(task01);
    taskExecutor.execute(task02);
    taskExecutor.execute(task03);
    taskExecutor.execute(task04);
    System.out.println("Tasks launched...");

    /* Close the pool */
    taskExecutor.shutdown();

    /*
     * Wait tasks termination (limit waiting to 15 minutes) and then display
     * processing state
     */
    boolean terminationState = taskExecutor.awaitTermination(15, TimeUnit.MINUTES);
    if (terminationState) {
      System.out.println("All tasks have finished their processing under the timeout !");
    } else {
      System.out.println("All tasks do not have finished their processing until the timeout !");
    }
View Full Code Here

   *        Command line
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    /* Create and configure a task pool manager (task executor) */
    ForkJoinPool taskExecutor = new ForkJoinPool();
    // Indicate to the task executor to use all processor of the current
    // machine
    taskExecutor.setParallelism(Runtime.getRuntime().availableProcessors());
    // In this sample tasks used here do not joined the we can disable the
    // AsyncMode (documentation
    // extract :
    // Establishes local first-in-first-out scheduling mode for forked tasks
    // that are never joined. This mode may be more appropriate than default
    // locally stack-based mode in applications in which worker threads only
    // process asynchronous tasks. This method is designed to be invoked
    // only when the pool is quiescent, and typically only before any tasks
    // are submitted. The effects of invocations at other times may be
    // unpredictable.)
    taskExecutor.setAsyncMode(false);
    // Indicate to the task executor to maintain parallelism
    taskExecutor.setMaintainsParallelism(true);

    /* Create and launch tasks with the task executor */
    FileCounterRecursiveAction task01 = new FileCounterRecursiveAction(new File("C:\\"));
    FileCounterRecursiveAction task02 = new FileCounterRecursiveAction(new File("D:\\"));
    FileCounterRecursiveAction task03 = new FileCounterRecursiveAction(new File("E:\\"));
    // Explicit invalid path in order that the task fail !
    FileCounterRecursiveAction task04 = new FileCounterRecursiveAction(new File("A:\\"));
    taskExecutor.execute(task01);
    taskExecutor.execute(task02);
    taskExecutor.execute(task03);
    taskExecutor.execute(task04);
    System.out.println("Tasks launched...");

    /* Close the pool */
    taskExecutor.shutdown();

    /*
     * Wait tasks termination (limit waiting to 15 minutes) and then display
     * processing state
     */
    boolean terminationState = taskExecutor.awaitTermination(15, TimeUnit.MINUTES);
    if (terminationState) {
      System.out.println("All tasks have finished their processing under the timeout !");
    } else {
      System.out.println("All tasks do not have finished their processing until the timeout !");
    }
View Full Code Here

    private ForkJoinPool forkJoinPool;

    @Before
    public void setUp() throws Exception {
        forkJoinPool = new ForkJoinPool(1);
    }
View Full Code Here

TOP

Related Classes of jsr166y.ForkJoinPool$EmptyTask

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.