Package thread.concurrencyCookbook.chapter5.recipe03

Examples of thread.concurrencyCookbook.chapter5.recipe03.FolderProcessor


  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


   
    /*
     * Launch 100 Consumer tasks
     */
    for (int i=0; i<THREADS; i++){
      Consumer consumer=new Consumer("Consumer "+i,buffer);
      consumerThreads[i]=new Thread(consumer);
      consumerThreads[i].start();
    }
   
    /*
 
View Full Code Here

   
    /*
     * Launch 100 Producer tasks
     */
    for (int i=0; i<THREADS; i++) {
      Producer producer=new Producer("Producer: "+i,buffer);
      producerThreads[i]=new Thread(producer);
      producerThreads[i].start();
    }
   
    /*
 
View Full Code Here

    MyThreadFactory myFactory=new MyThreadFactory("MyThreadFactory");
 
    /*
     * Crate a Task
     */
    MyTask task=new MyTask();
   
    /*
     * Create a Thread using the Factory to execute the Task
     */
    Thread thread=myFactory.newThread(task);
View Full Code Here

   */
  public static void main(String[] args) throws Exception {
    /*
     * Create a Factory
     */
    MyThreadFactory myFactory=new MyThreadFactory("MyThreadFactory");
 
    /*
     * Crate a Task
     */
    MyTask task=new MyTask();
   
    /*
     * Create a Thread using the Factory to execute the Task
     */
    Thread thread=myFactory.newThread(task);
   
    /*
     * Start the Thread
     */
    thread.start();
 
View Full Code Here

    /*
     * Create and launch a thread every 200 milliseconds. After each creation,
     * show information about the semaphore
     */
    for (int i=0; i<threads.length; i++) {
      Task task=new Task(semaphore);
      threads[i]=new Thread(task);
      threads[i].start();
     
      TimeUnit.MILLISECONDS.sleep(200);
     
View Full Code Here

  /**
   * @param args
   */
  public static void main(String[] args) {
   
    TaskAtomic atomicTask=new TaskAtomic();

    TaskLock lockTask=new TaskLock();
   
    int numberThreads=50;
    Thread threads[]=new Thread[numberThreads];
View Full Code Here

   */
  public static void main(String[] args) {
   
    TaskAtomic atomicTask=new TaskAtomic();

    TaskLock lockTask=new TaskLock();
   
    int numberThreads=50;
    Thread threads[]=new Thread[numberThreads];
    Date begin,end;
   
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

TOP

Related Classes of thread.concurrencyCookbook.chapter5.recipe03.FolderProcessor

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.