Advertisement
JeffGrigg

Two Threads by Inheritance

Nov 4th, 2018
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.50 KB | None | 0 0
  1. public class MyClass extends Thread {
  2.     private final String _taskName;
  3.     MyClass(String taskName) {
  4.         _taskName = taskName;
  5.     }
  6.     @Override
  7.     public void run() {
  8.         System.out.println(_taskName);
  9.     }
  10.     public static void main(String[] args) throws InterruptedException {
  11.         MyClass thread1 = new MyClass("Task1");
  12.         MyClass thread2 = new MyClass("Task2");
  13.         thread1.start();
  14.         thread2.start();
  15.         thread1.join();
  16.         thread2.join();
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement