Package com.packtpub.java7.concurrency.chapter5.recipe05.util

Examples of com.packtpub.java7.concurrency.chapter5.recipe05.util.TaskManager


   * Main method of the class
   */
  public static void main(String[] args) {
   
    // Generate a document with 100 lines and 1000 words per line
    DocumentMock mock=new DocumentMock();
    String[][] document=mock.generateDocument(100, 1000, "the");
 
    // Create a DocumentTask
    DocumentTask task=new DocumentTask(document, 0, 100, "the");
   
    // Create a ForkJoinPool
View Full Code Here


  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();
    System.out.printf("System: %d files found.\n",results.size());
   
    results=apps.join();
    System.out.printf("Apps: %d files found.\n",results.size());
   
    results=documents.join();
    System.out.printf("Documents: %d files found.\n",results.size());
   

  }
View Full Code Here

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

TOP

Related Classes of com.packtpub.java7.concurrency.chapter5.recipe05.util.TaskManager

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.