All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.doip.cluster.flowcontrol.CustomRejectedExecutionHandler Maven / Gradle / Ivy

The newest version!
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 - 2024 Weber Informatics LLC | Privacy Policy