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

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

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

@Override public String call() throws Exception {

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

Future<String> submit = poolExecutor.submit(callable);

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

猜你喜欢

转载自blog.csdn.net/wb_zjp283121/article/details/89398387