Advertisement
alexandrecoussy

Untitled

May 6th, 2022
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.         Runnable r1 = () -> {
  2.             System.out.println("thread 1 start");
  3.             sleep(3000);
  4.             System.out.println("thread 1 stop");
  5.         };
  6.  
  7.         Runnable r2 = () -> {
  8.             System.out.println("thread 2 start");
  9.             sleep(3000);
  10.             System.out.println("thread 2 stop");
  11.         };
  12.  
  13.         Runnable r3 = () -> {
  14.             System.out.println("thread 3 start");
  15.             sleep(3000);
  16.             System.out.println("thread 3 stop");
  17.         };
  18.  
  19.         Thread t1 = new Thread(r1);
  20.         Thread t2 = new Thread(r2);
  21.         Thread t3 = new Thread(r3);
  22.  
  23.         t1.start();
  24.         t2.start();
  25.         System.out.println("--- affichage immédiat après démarrage t1 et t2 ---");
  26.  
  27.         t1.join();
  28.         t2.join();
  29.  
  30.         System.out.println("--- je ne reprend pas tant que t1 n'est pas terminé ---");
  31.         t3.start();
  32.         System.out.println("--- affiché quasi au même moment que démarrage t3 ---");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement