java并发

This commit is contained in:
罗祥
2019-11-29 17:58:46 +08:00
parent 3f371f110d
commit 538f89ebc9
14 changed files with 913 additions and 114 deletions

View File

@ -0,0 +1,23 @@
package com.heibaiying.threadPool;
import java.util.concurrent.*;
public class J5_GetThreadResult {
static class CustomThread implements Callable<String> {
@Override
public String call() throws Exception {
Thread.sleep(3000);
return "线程返回结果";
}
}
public static void main(String[] args) throws ExecutionException, InterruptedException {
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<String> submit = executorService.submit(new CustomThread());
String result = submit.get();
System.out.println(result);
executorService.shutdown();
}
}