Examples of Task


Examples of com.packtpub.java7.concurrency.chapter8.recipe03.task.Task

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

Examples of com.packtpub.java7.concurrency.chapter8.recipe04.task.Task

   
    /*
     * Create and launch three tasks
     */
    for (int i=0; i<3; i++) {
      Task task=new Task(i+1, phaser);
      Thread thread=new Thread(task);
      thread.start();
    }
   
    /*
 
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter8.recipe05.task.Task

    /*
     * Create and submit ten tasks
     */
    Random random=new Random();
    for (int i=0; i<10; i++) {
      Task task=new Task(random.nextInt(10000));
      executor.submit(task);
    }
   
    /*
     * Write information about the executor
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter8.recipe06.task.Task

    int array[]=new int[10000];
   
    /*
     * Create a new task
     */
    Task task1=new Task(array,0,array.length);
   
    /*
     * Execute the task in the Fork/Join pool
     */
    pool.execute(task1);
   
    /*
     * Wait for the finalization of the task writing information
     * about the pool every second
     */
    while (!task1.isDone()) {
      showLog(pool);
      TimeUnit.SECONDS.sleep(1);
    }
   
    /*
 
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter8.recipe07.task.Task

     * Create and launch five Task objects
     */
    Thread threads[]=new Thread[5];
    for (int i=0; i<threads.length; i++) {
      logger.log(Level.INFO,"Launching thread: "+i);
      Task task=new Task();
      threads[i]=new Thread(task);
      logger.log(Level.INFO,"Thread created: "+threads[i].getName());
      threads[i].start();
    }
   
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter8.recipe08.task.Task

     * Executes the threads. There is a problem with this
     * block of code. It uses the run() method instead of
     * the start() method.
     */
    for (int i=0; i<10; i++) {
      Task task=new Task(lock);
      Thread thread=new Thread(task);
      thread.run();
    }

  }
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter9.recipe06.task.Task

    Thread threads[]=new Thread[1000];
    Date start,end;
   
    start=new Date();
    for (int i=0; i<threads.length; i++) {
      Task task=new Task();
      threads[i]=new Thread(task);
      threads[i].start();
    }
   
    for (int i=0; i<threads.length; i++) {
      try {
        threads[i].join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
    end=new Date();
    System.out.printf("Main: Threads: %d\n",(end.getTime()-start.getTime()));
   
    ThreadPoolExecutor executor=(ThreadPoolExecutor)Executors.newCachedThreadPool();
   
    start=new Date();
    for (int i=0; i<threads.length; i++) {
      Task task=new Task();
      executor.execute(task);
    }
    executor.shutdown();
    try {
      executor.awaitTermination(1, TimeUnit.DAYS);
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter9.recipe09.task.Task

  /**
   * @param args
   */
  public static void main(String[] args) {
    int array[]=new int[100000];
    Task task=new Task(array);
    ThreadPoolExecutor executor=(ThreadPoolExecutor)Executors.newCachedThreadPool();
   
    Date start,end;
    start=new Date();
    executor.execute(task);
View Full Code Here

Examples of com.packtpub.java7.concurrency.chapter9.recipe10.task.Task

   * @param args
   */
  public static void main(String[] args) {
    ReentrantLock lock=new ReentrantLock();
    for (int i=0; i<10; i++) {
      Task task=new Task(lock);
      Thread thread=new Thread(task);
      thread.start();
    }
  }
View Full Code Here

Examples of com.packtpub.java7.concurrncy.chapter9.recipe10.task.Task

  /**
   * @param args
   */
  public static void main(String[] args) {
    for (int i=0; i<20; i++){
      Task task=new Task();
      Thread thread=new Thread(task);
      thread.start();
    }

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.