简单应用:
Future<Boolean> futureVideo = ThreadPoolHolder.Pool_Tread.submit(() -> {
try {
Result resultVideo = getSystemPicInfo(json, result);
log.info("获取影像系统返回的结果为{}", resultVideo.success);
cond.countDown();
return resultVideo.success;
} catch (Exception e) {
log.info("获取影像接口出现异常{}", e.getMessage());
cond.countDown();
return false;
}
});
public class ThreadPoolHolder {
private static final Logger logger = LoggerFactory.getLogger(ThreadPoolHolder.class);
//线程池核心线程数
private static final int corePoolSize = 40;
//线程池的最大数
private static final int maximumPoolSize = 40;
//线程池空闲线程的最大存活时间
private static final long keepAliveTime = 60L;
public static final ExecutorService Pool_Tread = new ThreadPoolExecutor(corePoolSize,maximumPoolSize,keepAliveTime,
TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>()){
};
}
简单地调用,可以通过
futureCrm.get()
进行判断。
bilibili:https://www.bilibili.com/video/BV1ZK4y1s7aH?p=2