Java Thread run() vs start()

package com.bawi.threads;

public class ThreadRunVsStart {
    public static void main(String[] args) {
        // start new thread and task will be executed in the new thread
        new Thread(() -> System.out.println(Thread.currentThread().getName() + " start")).start(); 

        // common mistake: execute task in the current thread (does not start new one)
        new Thread(() -> System.out.println(Thread.currentThread().getName() + " run")).run(); 
// Thread-0 start
// main run

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s