JeffGrigg icon

Two Threads by Inheritance

JeffGrigg | PRO | 11/04/18 09:14:12 PM UTC | 0 ⭐ | 1006 👁️ | Never ⏰ | []
Java 5 |

0 B

|

None

|

0 👍

/

0 👎

public class MyClass extends Thread {
    private final String _taskName;
    MyClass(String taskName) {
        _taskName = taskName;
    }
    @Override
    public void run() {
        System.out.println(_taskName);
    }
    public static void main(String[] args) throws InterruptedException {
        MyClass thread1 = new MyClass("Task1");
        MyClass thread2 = new MyClass("Task2");
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎