首页>代码>spring线程池ThreadPoolExecutor配置并且得到任务执行的结果>/zuidaima_ThreadPoolTaskExecutor/src/main/java/com/zuidaima/threadpool/ThreadPoolTask.java
package com.zuidaima.threadpool;

import java.io.Serializable;
import java.util.concurrent.Callable;

public class ThreadPoolTask implements Callable<String>, Serializable {

	private static final long serialVersionUID = 0;

	// 保存任务所需要的数据
	private Object threadPoolTaskData;

	private static int consumeTaskSleepTime = 2000;

	public ThreadPoolTask(Object tasks) {
		this.threadPoolTaskData = tasks;
	}

	public synchronized String call() throws Exception {
		// 处理一个任务,这里的处理方式太简单了,仅仅是一个打印语句
		System.out.println("开始执行任务:" + threadPoolTaskData);
		String result = "";
		// //便于观察,等待一段时间
		try {
			// long r = 5/0;
			for (int i = 0; i < 100000000; i++) {

			}
			result = "OK";
		} catch (Exception e) {
			e.printStackTrace();
			result = "ERROR";
		}
		threadPoolTaskData = null;
		return result;
	}
}
最近下载更多
heweimin  LV12 2023年7月27日
2469095052  LV8 2022年5月27日
mylzdy  LV12 2022年5月12日
huasir2018  LV14 2020年5月25日
宇文笑  LV5 2019年8月29日
太阳暖人不暖心  LV7 2019年5月7日
1943815081  LV13 2019年1月2日
zinshao  LV12 2018年11月24日
h895413025  LV1 2018年11月13日
1633788059  LV12 2018年5月25日
最近浏览更多
yyh1252  LV8 2023年11月23日
heweimin  LV12 2023年7月27日
微信网友_15002431817 2023年1月17日
暂无贡献等级
1529860026  LV24 2022年9月5日
mylzdy  LV12 2022年5月12日
1234mama  LV19 2022年3月22日
shaoluyu  LV4 2022年3月18日
2469095052  LV8 2021年12月29日
gaojian0612  LV2 2021年11月23日
随便取个名字_哈哈  LV27 2021年11月7日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友