Two Threads by Inheritance
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
0 B
|👍
/👎