feat: 新增可计数的拒绝策略.

This commit is contained in:
2025-03-05 14:50:36 +08:00
parent f7e4400e37
commit af9c1c9622
6 changed files with 83 additions and 9 deletions

View File

@@ -9,6 +9,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/**
@@ -20,6 +21,9 @@ import java.util.function.Consumer;
*/
public abstract class AbstractStateMachine<S> extends AbstractStateManager<S> implements StateMachine<S> {
/**
* 状态机上下文
*/
protected final StateMachineContext<S> context;
/**
@@ -52,6 +56,9 @@ public abstract class AbstractStateMachine<S> extends AbstractStateManager<S> im
if (executor instanceof ExecutorService) {
ExecutorService es = (ExecutorService) executor;
es.shutdown();
if (!es.awaitTermination(10, TimeUnit.SECONDS)) {
es.shutdownNow();
}
} else if (executor instanceof AutoCloseable) {
AutoCloseable ac = (AutoCloseable) executor;
ac.close();