Package java.util.concurrent

Examples of java.util.concurrent.ForkJoinPool$ForkJoinWorkerThreadFactory


  /**
   * Main method of the example
  */
  public static void main(String[] args) {
    // Create the pool
    ForkJoinPool pool=new ForkJoinPool();
   
    // Create three FolderProcessor tasks for three diferent folders
    FolderProcessor system=new FolderProcessor("C:\\Windows", "log");
    FolderProcessor apps=new FolderProcessor("C:\\Program Files","log");
    FolderProcessor documents=new FolderProcessor("C:\\Documents And Settings","log");
   
    // Execute the three tasks in the pool
    pool.execute(system);
    pool.execute(apps);
    pool.execute(documents);
   
    // Write statistics of the pool until the three tasks end
    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 ((!system.isDone())||(!apps.isDone())||(!documents.isDone()));
   
    // Shutdown the pool
    pool.shutdown();
   
    // Write the number of results calculate by each task
    List<String> results;
   
    results=system.join();
View Full Code Here


    MyWorkerThreadFactory factory=new MyWorkerThreadFactory();
   
    /*
     * Create new ForkJoinPool, passing as parameter the factory created before
     */
    ForkJoinPool pool=new ForkJoinPool(4, factory, null, false);
   
    /*
     * Create and initializes the elements of the array
     */
    int array[]=new int[100000];
   
    for (int i=0; i<array.length; i++){
      array[i]=1;
    }
   
    /*
     * Create a new Task to sum the elements of the array
     */
    MyRecursiveTask task=new MyRecursiveTask(array,0,array.length);
   
    /*
     * Send the task to the ForkJoinPool
     */
    pool.execute(task);
   
   
    /*
     * Wait for the finalization of the task
     */
    task.join();
   
    /*
     * Shutdown the pool
     */
    pool.shutdown();
   
    /*
     * Wait for the finalization of the pool
     */
    pool.awaitTermination(1, TimeUnit.DAYS);
   
    /*
     * Write the result of the task
     */
    System.out.printf("Main: Result: %d\n",task.get());
View Full Code Here

public class FjPhaser {

  public static void main(String[] args) throws InterruptedException {
    final Phaser barrier = new Phaser(2);
    final ForkJoinPool pool = new ForkJoinPool();
    ForkJoinTask<?> t1 = pool.submit(ForkJoinTask.adapt(new Runnable() { // T1
      @Override
      public void run() {
        JArmus.register(barrier); // Is using the latch
        try {
          ForkJoinTask.adapt(new Runnable() { // T2
View Full Code Here

        }
      }
    };
    ForkJoinTask<?> t1 = ForkJoinTask.adapt(runnable);
    cell.set(t1);
    ForkJoinPool pool = new ForkJoinPool();
    pool.submit(t1);
    t1.get();
  }
View Full Code Here

public class CyclicFj {

  public static void main(String[] args) throws InterruptedException {
    final CyclicBarrier barrier = new CyclicBarrier(2);
    final ForkJoinPool pool = new ForkJoinPool();
    ForkJoinTask<?> t1 = pool.submit(ForkJoinTask.adapt(new Runnable() { // T1
      @Override
      public void run() {
        JArmus.register(barrier); // Is using the latch
        try {
          ForkJoinTask.adapt(new Runnable() { // T2
View Full Code Here

public class FjLatch {

  public static void main(String[] args) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final ForkJoinPool pool = new ForkJoinPool();
    ForkJoinTask<?> t1 = pool.submit(ForkJoinTask.adapt(new Runnable() { // T1
      @Override
      public void run() {
        JArmus.register(latch); // Is using the latch
        try {
          ForkJoinTask.adapt(new Runnable() { // T2
View Full Code Here

        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }));
    ForkJoinPool pool = new ForkJoinPool();
    pool.submit(f1.get());
    pool.submit(f2.get());
    f1.get().join();
    f2.get().join();
  }
View Full Code Here

public class FjLatchInvokeAll {

  public static void main(String[] args) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final ForkJoinPool pool = new ForkJoinPool();
    pool.invoke(ForkJoinTask.adapt(new Runnable() { // T
      @Override
      public void run() {
        ForkJoinTask.invokeAll(Arrays.asList(ForkJoinTask.adapt(new Runnable() {
          @Override
          public void run() {
View Full Code Here

        }
      }
    };
    ForkJoinTask<?> t1 = ForkJoinTask.adapt(runnable);
    cell.set(t1);
    ForkJoinPool pool = new ForkJoinPool();
    pool.submit(t1);
    t1.get();
  }
View Full Code Here

     * Allows timeouts for async operations
     */
    private static final GeneralTimer timer = GParsConfig.retrieveDefaultTimer("GParsTimeoutTimer", true);

    private static ForkJoinPool retrievePool() {
        final ForkJoinPool pool = (ForkJoinPool) GParsPool.retrieveCurrentPool();
        if (pool == null) throw new IllegalStateException("No ForkJoinPool available for the current thread");
        return pool;
    }
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.