jdk8异步
import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Supplier; /** * 基于jdk1.8实现任务异步处理 * */ public class JavaPromise { public static void main(String[] args) throws Throwable, ExecutionException { // 两个线程的线程池 ExecutorService executor = Executors.newFixedThreadPool(2); //jdk1.8方式写法 executor.submit(()->{ try { Thread.sleep(1000); System.err.println(444); } catch (InterruptedException e) { e.printStackTrace(); }finally { executor.shutdown(); } }); System.out.println("main thread is running"); } }