Java Stream How to - Create new Thread with Lambda








Question

We would like to know how to create new Thread with Lambda.

Answer

/*from   w  w w .j ava 2s .co  m*/

import java.util.concurrent.TimeUnit;

public class Main {
    public static void runThreadUseLambda() {
        new Thread(() -> System.out.println("")).start();
    }

    public static void runThreadUseInnerClass() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("");
            }
        }).start();
    }

    public static void main(String[] args) throws InterruptedException {
        runThreadUseLambda();
        runThreadUseInnerClass();

        TimeUnit.SECONDS.sleep(1);
    }
}