public class No3 { public static void main(String[] args) throws ExecutionException, InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(3); Future<Boolean> submita = executorService.submit(new aa()); Boolean aBoolean = submita.get(); if (aBoolean){ Future<Boolean> submitb = executorService.submit(new bb()); Boolean aBoolean1 = submitb.get(); if(aBoolean1){ Future<Boolean> submitc = executorService.submit(new cc()); } } executorService.shutdown(); } } class aa implements Callable<Boolean>{ @Override public Boolean call() throws Exception { System.out.println("a"); return true; } } class bb implements Callable<Boolean>{ @Override public Boolean call() throws Exception { System.out.println("b"); return true; } } class cc implements Callable<Boolean>{ @Override public Boolean call() throws Exception { System.out.println("c"); return true; } }
简单易懂