支持更多的拒绝策略类型. (#54)

pull/84/head
chen.ma 3 years ago
parent e969146eb4
commit c1726a4298

@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
/**
* Rejected policies.
@ -15,12 +16,12 @@ import java.util.concurrent.RejectedExecutionHandler;
public class RejectedPolicies {
/**
* ,
*
* @return
* , .
*/
public static RejectedExecutionHandler runsOldestTaskPolicy() {
return (r, executor) -> {
public static class RunsOldestTaskPolicy implements RejectedExecutionHandler {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
if (executor.isShutdown()) {
return;
}
@ -33,16 +34,17 @@ public class RejectedPolicies {
if (!newTaskAdd) {
executor.execute(r);
}
};
}
}
/**
* 使,
*
* @return
* 使, .
*/
public static RejectedExecutionHandler syncPutQueuePolicy() {
return (r, executor) -> {
public static class SyncPutQueuePolicy implements RejectedExecutionHandler {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
if (executor.isShutdown()) {
return;
}
@ -51,7 +53,8 @@ public class RejectedPolicies {
} catch (InterruptedException e) {
log.error("Adding Queue task to thread pool failed.", e);
}
};
}
}
}

@ -42,12 +42,12 @@ public enum RejectedTypeEnum {
/**
* ,
*/
RUNS_OLDEST_TASK_POLICY(5, RejectedPolicies.runsOldestTaskPolicy()),
RUNS_OLDEST_TASK_POLICY(5, new RejectedPolicies.RunsOldestTaskPolicy()),
/**
* 使,
*/
SYNC_PUT_QUEUE_POLICY(6, RejectedPolicies.syncPutQueuePolicy());
SYNC_PUT_QUEUE_POLICY(6, new RejectedPolicies.SyncPutQueuePolicy());
/**
*

Loading…
Cancel
Save