View Javadoc
1   package ch.hslu.exercises.sw05.input.ex3;
2   
3   import org.slf4j.LoggerFactory;
4   import org.slf4j.Logger;
5   
6   import java.util.stream.Stream;
7   
8   /**
9    * Demonstration von Join und Sleep - Aufgabe 3 - N1_EX_ThreadsSynch.
10   */
11  public class JoinAndSleep {
12  
13      private static final Logger LOG = LoggerFactory.getLogger(JoinAndSleep.class);
14  
15      /**
16       * Main-Demo.
17       *
18       * @param args not used.
19       * @throws InterruptedException wenn Warten unterbrochen wird.
20       */
21      public static void main(String[] args) throws InterruptedException {
22          Thread thread3 = new Thread(new JoinAndSleepTask("3", 400, null), "thread3");
23          Thread thread2 = new Thread(new JoinAndSleepTask("2", 300, thread3), "thread2");
24          Thread thread1 = new Thread(new JoinAndSleepTask("1", 200, thread2), "thread1");
25          Stream.of(thread1, thread2, thread3).forEach(Thread::start);
26  
27          Thread.sleep(800);
28          thread2.interrupt();
29  
30      }
31  }