Package com.packtpub.java7.concurrency.chapter1.recipe7.task

Examples of com.packtpub.java7.concurrency.chapter1.recipe7.task.CleanerTask


   * @param args
   */
  public static void main(String[] args) {
    // Creates a FileClock runnable object and a Thread
    // to run it
    FileClock clock=new FileClock();
    Thread thread=new Thread(clock);
   
    // Starts the Thread
    thread.start();
    try {
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

   * 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

   
    // Creates the Event data structure
    Deque<Event> deque=new ArrayDeque<Event>();
   
    // Creates the three WriterTask and starts them
    WriterTask writer=new WriterTask(deque);
    for (int i=0; i<3; i++){
      Thread thread=new Thread(writer);
      thread.start();
    }
   
View Full Code Here

    // Creates the Task
    Task task=new Task();
    // Creates the Thread
    Thread thread=new Thread(task);
    // Sets de uncaugh exceptio handler
    thread.setUncaughtExceptionHandler(new ExceptionHandler());
    // Starts the Thread
    thread.start();
   
    try {
      thread.join();
View Full Code Here

TOP

Related Classes of com.packtpub.java7.concurrency.chapter1.recipe7.task.CleanerTask

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.