public void scienceArchive(List<FinishedFile> list) throws Exception {
System.out.println("主线程开始。。。。。");
//开启子线程
ThreadFactory scanerThreadFactory = new ThreadFactoryBuilder()
.setNameFormat("子-%d").build();
ExecutorService scanerThreadPool = new ThreadPoolExecutor(2, 2,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(1024), scanerThreadFactory, new ThreadPoolExecutor.AbortPolicy());
scanerThreadPool.execute(() -> {
System.out.println("子线成:开始"+Thread.currentThread().getName());
for (VolumeFile v : volumeFileList) {
try {
this.settingSearchFile(v);
} catch (Exception e) {
log.error(String.format("scienceArchive-设置全文检索,时间:%s,参数:%s,异常信息:%s",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()),v.getId(),e.toString()));
}
}
System.out.println("子线成结束:"+Thread.currentThread().getName());
});
System.out.println("主线程结束。。。。。");
}
主线程执行完成,子线程可以慢慢执行