package test.current;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
public class TestCallable {
public static void main(String[] args) throws InterruptedException, ExecutionException {
List<Callable<List<Long>>> tasks = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Callable<List<Long>> task = new Callable<List<Long>>() {
@Override
public List<Long> call() throws Exception {
return Arrays.asList(1L,2L);
}
};
tasks.add(task);
}
List<Long> finalResults = new ArrayList<>(10);
List<Future<List<Long>>> results = ThreadPool.getThreadPool().invokeAll(tasks);
for(Future<List<Long>> ele : results) {
List<Long> list = ele.get();
finalResults.addAll(list);
}
System.out.println(finalResults);
}
}
package test.current;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class ThreadPool {
private static final int CORE_SIZE = 8;
private static final int MAX_SIZE = 12;
private static final long KEEP_ALIVE_TIME = 30;
private static final int QUEUE_SIZE = 50000;
private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(CORE_SIZE, MAX_SIZE, KEEP_ALIVE_TIME,
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(QUEUE_SIZE), new ThreadPoolExecutor.AbortPolicy());
public static ThreadPoolExecutor getThreadPool() {
return threadPool;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有