Advertisement
Josif_tepe

Untitled

Mar 30th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         MyThread t1 = new MyThread(1);
  4.         MyThread t2 = new MyThread(2);
  5.        t1.start();
  6.        t2.start();
  7.        if(t1.isAlive()) {
  8.            System.out.println("DA");
  9.            t1.interrupt();
  10.        }
  11.     }
  12. }
  13. class MyThread extends Thread {
  14.     int id;
  15.     public MyThread(int _id) {
  16.         id = _id;
  17.     }
  18.     @Override
  19.     public void run() {
  20.  
  21.         for(int i = 0; i < 20; i++) {
  22.             System.out.println("Thread " + id + " " + i);
  23.  
  24.         }
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement