一 线程类
package concurrent.policy;
/**
* @className: MyThread
* @description: 线程类
* @date: 2022/5/8
* @author: cakin
*/
public class MyThread implements Runnable {
private String threadName;
public MyThread(String threadName) {
this.threadName = threadName;
}
@Override
public void run() {
try {
System.out.println("threadName :" + this.threadName);
System.out.println(threadName + "执行了 1 秒钟...");
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public String getThreadName() {
return threadName;
}
public void setThreadName(String threadName) {
this.threadName = threadName;
}
}
二 自定义拒绝策略类
package concurrent.policy;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor