Package thread.concurrencyCookbook.chapter2.recipe05

Source Code of thread.concurrencyCookbook.chapter2.recipe05.Main

package thread.concurrencyCookbook.chapter2.recipe05;

import thread.concurrencyCookbook.chapter2.recipe05.PricesInfo;
import thread.concurrencyCookbook.chapter2.recipe05.Reader;
import thread.concurrencyCookbook.chapter2.recipe05.Writer;

/**
* Main class of the example
*
*/
public class Main {

  /**
   * Main class of the example
   * @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
    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);
    Thread threadWriter=new Thread(writer);
   
    // Starts the threads
    for (int i=0; i<5; i++){
      threadsReader[i].start();
    }
    threadWriter.start();
   
  }

}
TOP

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

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.