
org.bdware.doip.cluster.flowcontrol.CustomRejectedExecutionHandler Maven / Gradle / Ivy
package org.bdware.doip.cluster.flowcontrol;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
public class CustomRejectedExecutionHandler implements RejectedExecutionHandler {
Logger LOGGER = LogManager.getLogger(CustomRejectedExecutionHandler.class);
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
// 自定义处理逻辑
LOGGER.info("Task " + r.toString() + " rejected from " + executor.toString());
// 将被拒绝的任务重新放入队列中等待执行
try {
Thread.sleep(1000);
executor.getQueue().put(r);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy