Java

자바 ExecutorService

NaHyungMin 2020. 11. 3. 16:35

결과값이 없는 비동기. C#으로 치면 Action인듯.

 

package main.java.com;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExecutorServiceMain {
    public static void main(String[] args) {
        System.out.println("start");

        ExecutorService executorService = Executors.newCachedThreadPool();

        executorService.execute(() -> {
            try{
                Thread.sleep(10);
                System.out.println("result2");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        System.out.println("result1");
    }
}