多线程-线程池执行多线程,如何保证线程执行完成后再执行下面的业务逻辑

public static void main(String[] args) throws ExecutionException, InterruptedException {

ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(3, 3, 60L, TimeUnit.SECONDS, new LinkedBlockingDeque<>()); Callable callable = new Callable() {

@Override public String call() throws Exception {

System.out.println(1); Thread.sleep(1000); return "2"; } };

Future submit = poolExecutor.submit(callable);

String s = submit.get();//等线程执行完返回数据 System.out.println(s); }

你可能感兴趣的:(多线程-线程池执行多线程,如何保证线程执行完成后再执行下面的业务逻辑)