Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zad1;
- /*
- * author Marta Korzeniowska
- *
- * */
- class MyThread extends Thread {
- private int cnt;
- private String str;
- MyThread(int c, String s) {
- cnt = c;
- str = s;
- }
- @Override
- public void run() {
- try {
- for (int i = 0; i < cnt; i++) {
- System.out.println(str);
- Thread.sleep((long) (Math.random() * 1000));
- }
- } catch (InterruptedException ignored) {
- }
- }
- }
- package zad1;
- public class Main {
- public static void main(String[] args) throws InterruptedException {
- System.out.println("===== start ====");
- MyThread t1 = new MyThread(10, "zad1");
- MyThread t2 = new MyThread(10, "Pong");
- MyThread t3 = new MyThread(10, "PENG");
- t1.start();
- t2.start();
- t3.start();
- t1.join();
- t2.join();
- t3.join();
- System.out.println("==== stop ====");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement