Advertisement
Josif_tepe

Untitled

Mar 24th, 2022
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         t t1 = new t(1);
  4.         t t2 = new t(2);
  5.         t1.start();
  6.         t2.start();
  7.         try {
  8.             t1.join(5000);
  9.             System.out.println(t1.isAlive());
  10.             t2.join(5000);
  11.             System.out.println(t2.isAlive());
  12.         }
  13.         catch (Exception ex) {
  14.             ex.printStackTrace();
  15.         }
  16.  
  17.  }
  18. }
  19. class t extends  Thread {
  20.     int id;
  21.     public t(int _id) {
  22.         id = _id;
  23.     }
  24.     @Override
  25.     public void run() {
  26.         for(int i = 0; i < 10; i++) {
  27.             System.out.println("Thread " + id +  " " + i);
  28.             try {
  29.                 Thread.sleep(100);
  30.             }
  31.             catch (Exception ex) {
  32.                 ex.printStackTrace();
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement