Advertisement
JeffGrigg

Two Threads without Inheritance

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