直接上代码
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @author 言曌
* @date 2020/12/16 6:22 下午
*/
/**
* 业务线程池
*/
class BusinessThread implements Runnable {
// 业务参数
private String param1;
private String param2;
private String param3;
public BusinessThread(String param1, String param2, String param3) {
this.param1 = param1;
this.param2 = param2;
this.param3 = param3;
}
@Override
public void run() {
// TODO 业务逻辑
System.out.println("Hello World!!!!!");
System.out.println(param1);
System.out.println(param2);
System.out.println(param3);
}
public String getParam1() {
return param1;
}
public void setParam1(String param1) {
this.param1 = param1;
}
public String getParam2() {
return param2;
}
public void setParam2(String param2) {
this.param2 = param2;
}
public String getParam3() {
return param3;
}
public void setParam3(String param3) {
this.param3 = param3;
}
}
public class Demo {
private static BlockingQueue<Runnable> bqueue = new ArrayBlockingQueue<Runnable>(1000000);
private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 10, 2000, TimeUnit.MILLISECONDS,
bqueue, new ThreadPoolExecutor.CallerRunsPolicy());
public static void main(String[] args) {
// 不需要返回用execute
threadPoolExecutor.execute(new BusinessThread("张三", "男", "18"));
// 需要返回用submit
//threadPoolExecutor.submit(new BusinessThread());
}
}
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏