JoinAndSleep.java
package ch.hslu.exercises.sw05.input.ex3;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import java.util.stream.Stream;
/**
* Demonstration von Join und Sleep - Aufgabe 3 - N1_EX_ThreadsSynch.
*/
public class JoinAndSleep {
private static final Logger LOG = LoggerFactory.getLogger(JoinAndSleep.class);
/**
* Main-Demo.
*
* @param args not used.
* @throws InterruptedException wenn Warten unterbrochen wird.
*/
public static void main(String[] args) throws InterruptedException {
Thread thread3 = new Thread(new JoinAndSleepTask("3", 400, null), "thread3");
Thread thread2 = new Thread(new JoinAndSleepTask("2", 300, thread3), "thread2");
Thread thread1 = new Thread(new JoinAndSleepTask("1", 200, thread2), "thread1");
Stream.of(thread1, thread2, thread3).forEach(Thread::start);
Thread.sleep(800);
thread2.interrupt();
}
}