1.线程池简介
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class CallableDemo {
public static void main(String[] args) throws InterruptedException, ExecutionException {
//执行服务器
ExecutorService es = Executors.newCachedThreadPool();
Future<String> f = es.submit(new cDemo());
System.out.println(f.get());
}
}
class cDemo implements Callable<String>{
@Override
public String call() throws Exception {
return "Tom";
}
}
2. 自定义线程池
2.1 简单介绍