Package com.packtpub.java7.concurrency.chapter5.recipe01.core

Examples of com.packtpub.java7.concurrency.chapter5.recipe01.core.Main


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


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

    // Create a ThreadGroup
    ThreadGroup threadGroup = new ThreadGroup("Searcher");
    Result result=new Result();

    // Create a SeachTask and 10 Thread objects with this Runnable
    SearchTask searchTask=new SearchTask(result);
    for (int i=0; i<5; i++) {
      Thread thread=new Thread(threadGroup, searchTask);
View Full Code Here

    // Create a ThreadGroup
    ThreadGroup threadGroup = new ThreadGroup("Searcher");
    Result result=new Result();

    // Create a SeachTask and 10 Thread objects with this Runnable
    SearchTask searchTask=new SearchTask(result);
    for (int i=0; i<5; i++) {
      Thread thread=new Thread(threadGroup, searchTask);
      thread.start();
      try {
        TimeUnit.SECONDS.sleep(1);
View Full Code Here

   * and then, interrupts the Thread
   * @param args
   */
  public static void main(String[] args) {
    // Creates the Runnable object and the Thread to run it
    FileSearch searcher=new FileSearch("C:\\","autoexec.bat");
    Thread thread=new Thread(searcher);
   
    // Starts the Thread
    thread.start();
   
View Full Code Here

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

    // Creates and starts a DataSourceLoader runnable object
    DataSourcesLoader dsLoader = new DataSourcesLoader();
    Thread thread1 = new Thread(dsLoader,"DataSourceThread");
    thread1.start();

    // Creates and starts a NetworkConnectionsLoader runnable object
    NetworkConnectionsLoader ncLoader = new NetworkConnectionsLoader();
View Full Code Here

    DataSourcesLoader dsLoader = new DataSourcesLoader();
    Thread thread1 = new Thread(dsLoader,"DataSourceThread");
    thread1.start();

    // Creates and starts a NetworkConnectionsLoader runnable object
    NetworkConnectionsLoader ncLoader = new NetworkConnectionsLoader();
    Thread thread2 = new Thread(ncLoader,"NetworkConnectionLoader");
    thread2.start();

    // Wait for the finalization of the two threads
    try {
View Full Code Here

  public void run() {
   
    // Writes 100 events
    for (int i=1; i<100; i++) {
      // Creates and initializes the Event objects
      Event event=new Event();
      event.setDate(new Date());
      event.setEvent(String.format("The thread %s has generated an event",Thread.currentThread().getId()));
     
      // Add to the data structure
      deque.addFirst(event);
      try {
        // Sleeps during one second
View Full Code Here

      Thread thread=new Thread(writer);
      thread.start();
    }
   
    // Creates a cleaner task and starts them
    CleanerTask cleaner=new CleanerTask(deque);
    cleaner.start();

  }
View Full Code Here

   * Main method of the example
   * @param args
   */
  public static void main(String[] args) {
    // Creates a task
    SafeTask task=new SafeTask();
   
    // Creates and start three Thread objects for that Task
    for (int i=0; i<3; i++){
      Thread thread=new Thread(task);
      try {
View Full Code Here

   * three Thread objects that run it.
   * @param args
   */
  public static void main(String[] args) {
    // Creates the unsafe task
    UnsafeTask task=new UnsafeTask();
   
    // Throw three Thread objects
    for (int i=0; i<3; i++){
      Thread thread=new Thread(task);
      thread.start();
View Full Code Here

TOP

Related Classes of com.packtpub.java7.concurrency.chapter5.recipe01.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.