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

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


  /**
   * @param args
   */
  public static void main(String[] args) {
    Lock lock=new ReentrantLock();
    Task1 task1=new Task1(lock);
    Task2 task2=new Task2(lock);
    Thread threads[]=new Thread[10];
   
    Date begin, end;
   
View Full Code Here


   * @param args
   */
  public static void main(String[] args) {
    Lock lock=new ReentrantLock();
    Task1 task1=new Task1(lock);
    Task2 task2=new Task2(lock);
    Thread threads[]=new Thread[10];
   
    Date begin, end;
   
    begin=new Date();
View Full Code Here

    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

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

      e.printStackTrace();
    }
    end=new Date();
    System.out.printf("Main: Executor: %d\n",(end.getTime()-start.getTime()));
   
    TaskFJ taskFJ=new TaskFJ(array,1,100000);
    ForkJoinPool pool=new ForkJoinPool();
    start=new Date();
    pool.execute(taskFJ);
    pool.shutdown();
    try {
View Full Code Here

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

  @Override
  public void run() {

    System.out.printf("%s: Getting the connection...\n",Thread.currentThread().getName());
    DBConnectionOK connection=DBConnectionOK.getConnection();
    System.out.printf("%s: End\n",Thread.currentThread().getName());
  }
View Full Code Here

   * @param args
   */
  public static void main(String[] args) {

    // Creates an object to store the prices
    PricesInfo pricesInfo=new PricesInfo();
   
    Reader readers[]=new Reader[5];
    Thread threadsReader[]=new Thread[5];
   
    // Creates five readers and threads to run them
View Full Code Here

  public static void main(String[] args) {

    // Creates an object to store the prices
    PricesInfo pricesInfo=new PricesInfo();
   
    Reader readers[]=new Reader[5];
    Thread threadsReader[]=new Thread[5];
   
    // Creates five readers and threads to run them
    for (int i=0; i<5; i++){
      readers[i]=new Reader(pricesInfo);
      threadsReader[i]=new Thread(readers[i]);
    }
   
    // Creates a writer and a thread to run it
    Writer writer=new Writer(pricesInfo);
View Full Code Here

      readers[i]=new Reader(pricesInfo);
      threadsReader[i]=new Thread(readers[i]);
    }
   
    // Creates a writer and a thread to run it
    Writer writer=new Writer(pricesInfo);
    Thread threadWriter=new Thread(writer);
   
    // Starts the threads
    for (int i=0; i<5; i++){
      threadsReader[i].start();
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.