Package java.util.concurrent

Examples of java.util.concurrent.ForkJoinPool$ForkJoinWorkerThreadFactory


        Issue test2 = new Issue(Issue.getInitIssue());
        // Check the number of available processors
        int nThreads = Runtime.getRuntime().availableProcessors();
        System.out.println(nThreads);
        SelectMaxInArray t = new SelectMaxInArray(test);
        ForkJoinPool pool = new ForkJoinPool(nThreads);
        Long start = System.nanoTime();
        pool.invoke(t);
        Long end = System.nanoTime();
        long result = t.result;
        System.out.println("Done. Result: " + result + "time1 : " + (end - start));
        Long start2 = System.nanoTime();
        long result2 = test2.solveSequentially();
View Full Code Here


        System.out.println(nThreads);
        int [] arr1 = Issue.getInitIssue();
        int[] arr2 = new int[arr1.length];
        System.arraycopy(arr1, 0, arr2, 0, arr1.length-1);
        MergeSort t = new MergeSort(Issue.getInitIssue(),0,arr1.length-1);
        ForkJoinPool pool = new ForkJoinPool(nThreads);
        Long start = System.nanoTime();
        pool.invoke(t);
        Long end = System.nanoTime();
        int[] result = t.getResult();
        System.out.println("Done. Result: time1 : " + (end - start));
        Long start2 = System.nanoTime();
        Arrays.sort(arr2, 0, arr1.length);
View Full Code Here

    public static void main(String[] args) {
        long[] anArray = new long[100000];
        for (int i = 0; i < anArray.length - 1; i++)
            anArray[i] = i;
        RecursiveAction mainTask = new IncrementTask(anArray, 0, anArray.length);
        ForkJoinPool mainPool = new ForkJoinPool();
        mainPool.invoke(mainTask);
    }
View Full Code Here

    public static void main(String[] args) {
        int[] anArray = new int[Integer.MAX_VALUE/10];
        assert anArray[Integer.MAX_VALUE/10] == 0;
        RecursiveAction mainTask = new IncrementTask (anArray, 0, anArray.length);
        ForkJoinPool mainPool = new ForkJoinPool();
        mainPool.invoke(mainTask);
        assert anArray[Integer.MAX_VALUE/10] == 1;
        System.out.println(mainPool.getActiveThreadCount());
        System.out.println(mainPool.getStealCount());
    }
View Full Code Here

        Random r = new Random();
        for (int i = 0; i < anArray.length; i++) {
            anArray[i] = r.nextInt(10);
        }
        RecursiveTask<Integer> task = new SumArray(anArray, 0, anArray.length);
        ForkJoinPool mainPool = new ForkJoinPool();
        Future<Integer> future = mainPool.submit(task);
        System.out.println(mainPool.getActiveThreadCount());
        System.out.println(mainPool.getStealCount());
        System.out.println(future.get());
    }
View Full Code Here

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

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

   
    // 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("PeriodictskExecution: Thread Count: %d\n",pool.getActiveThreadCount());
      System.out.printf("PeriodictskExecution: Thread Steal: %d\n",pool.getStealCount());
      System.out.printf("PeriodictskExecution: 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("PeriodictskExecution: The process has completed normally.\n");
    }
View Full Code Here

     
      InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
     
      this.entries = new ConcurrentHashMap<String, Map<String, Object>>();
      //this.entries = new ConcurrentHashMap<String, Object>();
      this.pool = new ForkJoinPool();
      this.observerTask = new ObserverTask<Integer, org.flowforwarding.warp.jcontroller.restapi.RestApiTask>();
     
      Timer timer = new HashedWheelTimer();
     
       this.handlerTask = new ChannelHandler(timer, 0, 0, 20);
View Full Code Here

  
   protected void processRequest (String jsonRequest, boolean isDelete) {
     
      Map<String, Map<String, Object>> entries = (Map<String, Map<String, Object>>)getContext().getAttributes().get("entries");
      //Map<String, Object> entries = (Map<String, Object>)getContext().getAttributes().get("entries");
      ForkJoinPool pool = (ForkJoinPool) getContext().getAttributes().get("pool");
      ObserverTask<Integer, RestApiTask> observerTask = (ObserverTask<Integer, RestApiTask>) getContext().getAttributes().get("observerTask");
      ControllerRef controllerRef =  (ControllerRef)getContext().getAttributes().get("controllerRef");
      ForkJoinTask<Map<String, Map<String, Object>>> task2;
     

      if (entries == null)
         entries = new HashMap<>();
        
     
      if (isDelete) {
         Map <String, Object> delete = new HashMap();
         delete.put("DELETE", "YES");
         entries.put(jsonRequest, delete);
      }
     
      RecursiveTask <Map<String, Map<String, Object>>> task = new RestApiTask(jsonRequest, entries);
      if (observerTask !=null)
         observerTask.update((RestApiTask) task);
     
      /*if (pool != null)
         pool.execute(task);*/
     
      if (pool != null) {
         task2 = pool.submit(task);
         try {
            entries = task2.get();
         } catch (InterruptedException | ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
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.