Advertisement
Karenira

PAI- zadanie 1

Apr 3rd, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. package zad1;
  2. /*
  3.  * author Marta Korzeniowska
  4.  *
  5.  * */
  6. class MyThread extends Thread {
  7.     private int cnt;
  8.     private String str;
  9.  
  10.     MyThread(int c, String s) {
  11.         cnt = c;
  12.         str = s;
  13.     }
  14.     @Override
  15.     public void run() {
  16.         try {
  17.             for (int i = 0; i < cnt; i++) {
  18.                 System.out.println(str);
  19.                 Thread.sleep((long) (Math.random() * 1000));
  20.             }
  21.         } catch (InterruptedException ignored) {
  22.         }
  23.     }
  24. }
  25. package zad1;
  26.  
  27. public class Main {
  28.     public static void main(String[] args) throws InterruptedException {
  29.         System.out.println("===== start ====");
  30.         MyThread t1 = new MyThread(10, "zad1");
  31.         MyThread t2 = new MyThread(10, "Pong");
  32.         MyThread t3 = new MyThread(10, "PENG");
  33.         t1.start();
  34.         t2.start();
  35.         t3.start();
  36.         t1.join();
  37.         t2.join();
  38.         t3.join();
  39.         System.out.println("==== stop ====");
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement