Package com.packtpub.java7.concurrency.chapter8.recipe04.core

Examples of com.packtpub.java7.concurrency.chapter8.recipe04.core.Main


    ParkingCounter counter=new ParkingCounter(5);
   
    /*
     * Create and launch two sensors
     */
    Sensor1 sensor1=new Sensor1(counter);
    Sensor2 sensor2=new Sensor2(counter);
   
    Thread thread1=new Thread(sensor1);
    Thread thread2=new Thread(sensor2);
   
View Full Code Here


   
    /*
     * Create and launch two sensors
     */
    Sensor1 sensor1=new Sensor1(counter);
    Sensor2 sensor2=new Sensor2(counter);
   
    Thread thread1=new Thread(sensor1);
    Thread thread2=new Thread(sensor2);
   
    thread1.start();
View Full Code Here

    ForkJoinPool pool=new ForkJoinPool();
   
    /*
     * Task to increment the elements of the array
     */
    Task task=new Task("Task",array,0,array.length);
   
    /*
     * Send the task to the pool
     */
    pool.invoke(task);
 
View Full Code Here

   */
  public static void main(String[] args) throws Exception {
    /*
     * Create a task object
     */
    Task task = new Task();
   
    /*
     * Create an array to store the threads
     */
    Thread threads[] = new Thread[5];
View Full Code Here

   */
  public static void main(String[] args) throws Exception {
    /*
     * Create a Lock object
     */
    MyLock lock=new MyLock();
   
    /*
     * Create an array for five threads
     */
    Thread threads[]=new Thread[5];
   
    /*
     * Create and start five threads
     */
    for (int i=0; i<5; i++) {
      Task task=new Task(lock);
      threads[i]=new Thread(task);
      threads[i].start();
    }
   
    /*
     * Create a loop with 15 steps
     */
    for (int i=0; i<15; i++) {
      /*
       * Write info about the lock
       */
      System.out.printf("Main: Logging the Lock\n");
      System.out.printf("************************\n");
      System.out.printf("Lock: Owner : %s\n",lock.getOwnerName());
      System.out.printf("Lock: Queued Threads: %s\n",lock.hasQueuedThreads());
      if (lock.hasQueuedThreads()){
        System.out.printf("Lock: Queue Length: %d\n",lock.getQueueLength());
        System.out.printf("Lock: Queued Threads: ");
        Collection<Thread> lockedThreads=lock.getThreads();
        for (Thread lockedThread : lockedThreads) {
        System.out.printf("%s ",lockedThread.getName());
        }
        System.out.printf("\n");
      }
      System.out.printf("Lock: Fairness: %s\n",lock.isFair());
      System.out.printf("Lock: Locked: %s\n",lock.isLocked());
      System.out.printf("************************\n");
      /*
       * Sleep the thread for one second
       */
      TimeUnit.SECONDS.sleep(1);
 
View Full Code Here

   
    /*
     * Create and start five threads
     */
    for (int i=0; i<5; i++) {
      Task task=new Task(lock);
      threads[i]=new Thread(task);
      threads[i].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

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

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

    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

TOP

Related Classes of com.packtpub.java7.concurrency.chapter8.recipe04.core.Main

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.