用ThreadPoolExecutor的时候,又想知道被执行的任务的执行情况,这时就可以用FutureTask。
原创不易,转载请注明出处:spring线程池ThreadPoolExecutor配置并且得到任务执行的结果
代码下载地址:http://www.zuidaima.com/share/1724478138158080.htm
ThreadPoolTask
01 | package com.zuidaima.threadpool; |
02 |
03 | import java.io.Serializable; |
04 | import java.util.concurrent.Callable; |
05 |
06 | public class ThreadPoolTask implements Callable<String>, Serializable { |
07 |
08 | private static final long serialVersionUID = 0 ; |
09 |
10 | // 保存任务所需要的数据 |
11 | private Object threadPoolTaskData; |
12 |
13 | private static int consumeTaskSleepTime = 2000 ; |
14 |
15 | public ThreadPoolTask(Object tasks) { |
16 | this .threadPoolTaskData = tasks; |
17 | } |