将1000个excel拆分为10个任务,每个任务处理100个excel,使用线程池异步操作,每个任务执行完毕后发个消息或者记录一下,等所有任务执行完毕后,打成zip包,服务器新能好的话 可以拆分成更多任务
@EnableAsync
@Configuration
class TaskPoolConfig {
//线程池
@Bean("taskExecutor")
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(20);
executor.setQueueCapacity(200);
executor.setKeepAliveSeconds(60);
executor.setThreadNamePrefix("taskExecutor-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setAwaitTerminationSeconds(60);return executor;
}
}
@Component
public class Task {
//线程池异步处理
@Async("taskExecutor")
public void doTask(参数。。。) throws Exception {
你的业务逻辑。。。。。
}
}
public class Tests{@Autowired
private Task task;
@Test
public void test() throws Exception {
task.doTask(参数。。。);
}
}