Advertisement
Josif_tepe

Untitled

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