Package com.packtpub.java7.concurrency.chapter1.recipe1.task

Examples of com.packtpub.java7.concurrency.chapter1.recipe1.task.Calculator


  public static void main(String[] args) throws Throwable {
   
    /*
     * Create a Test object
     */
    ProducerConsumerTest test=new ProducerConsumerTest();
   
    /*
     * Execute the test
     */
    System.out.printf("Main: Starting the test\n");
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

    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

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

    //Launch 10 threads that make the operation with a different number
    for (int i=1; i<=10; i++){
      Calculator calculator=new Calculator(i);
      Thread thread=new Thread(calculator);
      thread.start();
    }
  }
View Full Code Here

    // Launch 10 threads to do the operation, 5 with the max
    // priority, 5 with the min
    threads=new Thread[10];
    status=new Thread.State[10];
    for (int i=0; i<10; i++){
      threads[i]=new Thread(new Calculator(i));
      if ((i%2)==0){
        threads[i].setPriority(Thread.MAX_PRIORITY);
      } else {
        threads[i].setPriority(Thread.MIN_PRIORITY);
      }
View Full Code Here

TOP

Related Classes of com.packtpub.java7.concurrency.chapter1.recipe1.task.Calculator

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.