Package thread.concurrencyCookbook.chapter2.recipe05

Examples of thread.concurrencyCookbook.chapter2.recipe05.Reader


   
    // Create a ForkJoinPool with the default constructor
    ForkJoinPool pool=new ForkJoinPool();
   
    // Create a Task to process the array
    SearchNumberTask task=new SearchNumberTask(array,0,1000,5,manager);
   
    // Execute the task
    pool.execute(task);

    // Shutdown the pool
View Full Code Here


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

    // Generate an array of 1000 integers
    ArrayGenerator generator=new ArrayGenerator();
    int array[]=generator.generateArray(1000);
   
    // Create a TaskManager object
    TaskManager manager=new TaskManager();
   
    // Create a ForkJoinPool with the default constructor
View Full Code Here

    // Generate an array of 1000 integers
    ArrayGenerator generator=new ArrayGenerator();
    int array[]=generator.generateArray(1000);
   
    // Create a TaskManager object
    TaskManager manager=new TaskManager();
   
    // Create a ForkJoinPool with the default constructor
    ForkJoinPool pool=new ForkJoinPool();
   
    // Create a Task to process the array
View Full Code Here

    /*
     * Write the results to the console
     */
    do {
      int counter=0;
      Event event;
      do {
        event=queue.poll();
        if (event!=null) counter++;
      } while (event!=null);
      System.out.printf("At %s you have read %d events\n",new Date(),counter);
View Full Code Here

   
    /*
     * Create the five tasks
     */
    for (int i=0; i<threads.length; i++){
      Task task=new Task(i+1, queue);
      threads[i]=new Thread(task);
    }

    /*
     * Execute the five tasks
View Full Code Here

  public static void main(String[] args) throws Exception {
   
    /*
     * Create a MyScheduledThreadPool object
     */
    MyScheduledThreadPoolExecutor executor=new MyScheduledThreadPoolExecutor(2);
   
    /*
     * Create a task object 
     */
    Task task=new Task();
   
    /*
     * Write the start date of the execution
     */
    System.out.printf("Main: %s\n",new Date());
   
    /*
     * Send to the executor a delayed task. It will be executed after 1 second of delay
     */
    executor.schedule(task, 1, TimeUnit.SECONDS);
   
    /*
     * Sleeps the thread three seconds
     */
    TimeUnit.SECONDS.sleep(3);
   
    /*
     * Create another task
     */
    task=new Task();
   
    /*
     * Write the actual date again
     */
    System.out.printf("Main: %s\n",new Date());
   
    /*
     * Send to the executor a delayed task. It will begin its execution after 1 second of dealy
     * and then it will be executed every three seconds
     */
    executor.scheduleAtFixedRate(task, 1, 3, TimeUnit.SECONDS);
   
    /*
     * Sleep the thread during ten seconds
     */
    TimeUnit.SECONDS.sleep(10);

    /*
     * Shutdown the executor
     */
    executor.shutdown();
   
    /*
     * Wait for the finalization of the executor
     */
    executor.awaitTermination(1, TimeUnit.DAYS);
   
    /*
     * Write a message indicating the end of the program
     */
    System.out.printf("Main: End of the program.\n");
View Full Code Here

    MyScheduledThreadPoolExecutor executor=new MyScheduledThreadPoolExecutor(2);
   
    /*
     * Create a task object 
     */
    Task task=new Task();
   
    /*
     * Write the start date of the execution
     */
    System.out.printf("Main: %s\n",new Date());
   
    /*
     * Send to the executor a delayed task. It will be executed after 1 second of delay
     */
    executor.schedule(task, 1, TimeUnit.SECONDS);
   
    /*
     * Sleeps the thread three seconds
     */
    TimeUnit.SECONDS.sleep(3);
   
    /*
     * Create another task
     */
    task=new Task();
   
    /*
     * Write the actual date again
     */
    System.out.printf("Main: %s\n",new Date());
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

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

TOP

Related Classes of thread.concurrencyCookbook.chapter2.recipe05.Reader

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.