Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package _12._11.task_01;
- import static java.lang.Thread.sleep;
- /**
- *
- * sleep(), join()
- *
- * main Thread startet folgende Threads:
- * 1. Order
- * 2. Cook
- * 3. Pizzaboy
- *
- * Jeder Thread macht folgendes:
- *
- * Drei mal alle 400 ms text (inklusive Name) ausgeben und terminieren
- * Koch soll auf das Terminieren von Bestellung warten
- * Lieferant soll auf das Terminieren von Koch warten
- *
- * Hinweis:
- * -Verwende annonyme innere Klasse oder Lambda Expression (wo es möglich ist)
- *
- */
- public class Task_01 {
- public static void callOut() {
- for (int i = 0; i < 3; i++) {
- try {
- sleep(400);
- } catch (InterruptedException e) { }
- System.out.println("I am the " + Thread.currentThread().getName());
- }
- }
- public static void main(String[] args) {
- Thread order = new Thread(Task_01::callOut, "Order");
- Thread cook = new Thread(() -> {
- // callOut();
- try {
- order.join();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- callOut();
- }, "Cook");
- Thread pizzaboy = new Thread(() -> {
- // callOut();
- try {
- cook.join(100L);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- callOut();
- }, "Pizzaboy");
- order.start();
- cook.start();
- pizzaboy.start();
- System.out.println("Main zu!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement