Package com.packtpub.java7.concurrency.chapter4.recipe7.core

Examples of com.packtpub.java7.concurrency.chapter4.recipe7.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

      return;
    }
   
    delete=false;
    do {
      Event e = deque.getLast();
      difference = date.getTime() - e.getDate().getTime();
      if (difference > 10000) {
        System.out.printf("Cleaner: %s\n",e.getEvent());
        deque.removeLast();
        delete=true;
     
    } while (difference > 10000);
    if (delete){
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

TOP

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