Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. package _12._11.task_01;
  2.  
  3. import static java.lang.Thread.sleep;
  4.  
  5. /**
  6. *
  7. * sleep(), join()
  8. *
  9. * main Thread startet folgende Threads:
  10. * 1. Order
  11. * 2. Cook
  12. * 3. Pizzaboy
  13. *
  14. * Jeder Thread macht folgendes:
  15. *
  16. * Drei mal alle 400 ms text (inklusive Name) ausgeben und terminieren
  17. * Koch soll auf das Terminieren von Bestellung warten
  18. * Lieferant soll auf das Terminieren von Koch warten
  19. *
  20. * Hinweis:
  21. * -Verwende annonyme innere Klasse oder Lambda Expression (wo es möglich ist)
  22. *
  23. */
  24.  
  25. public class Task_01 {
  26.  
  27. public static void callOut() {
  28. for (int i = 0; i < 3; i++) {
  29. try {
  30. sleep(400);
  31. } catch (InterruptedException e) { }
  32. System.out.println("I am the " + Thread.currentThread().getName());
  33. }
  34. }
  35.  
  36. public static void main(String[] args) {
  37.  
  38. Thread order = new Thread(Task_01::callOut, "Order");
  39.  
  40. Thread cook = new Thread(() -> {
  41. // callOut();
  42. try {
  43. order.join();
  44. } catch (InterruptedException e) {
  45. e.printStackTrace();
  46. }
  47. callOut();
  48. }, "Cook");
  49.  
  50. Thread pizzaboy = new Thread(() -> {
  51. // callOut();
  52. try {
  53. cook.join(100L);
  54. } catch (InterruptedException e) {
  55. e.printStackTrace();
  56. }
  57. callOut();
  58. }, "Pizzaboy");
  59.  
  60. order.start();
  61. cook.start();
  62. pizzaboy.start();
  63.  
  64. System.out.println("Main zu!");
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement