JeffGrigg icon

Two Threads without Inheritance

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

0 B

|

None

|

0 👍

/

0 👎

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

Comments

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

    0 B

    |

    👍

    /

    👎