是否有带有队列限制的 ExecutorService 实现以及用新队列成员替换旧队列成员的选项?

Is there an ExecutorService implementation with queue limit and an option to replace old queue members with new ones?

我需要一个 ExecutorService 实现,它可以限制可以排队的 Runnable 数量。我还希望能够控制在队列已满时提交新的可运行对象时发生的情况。理想情况下,我希望能够 select 一个策略,但只需删除队列前面的可运行对象并将新的可运行对象放在队列末尾就足够了。我确定一定有类似的东西已经实现了,我环顾四周但找不到任何东西。

使用DiscardOldestPolicy

A handler for rejected tasks that discards the oldest unhandled request and then retries execute, unless the executor is shut down, in which case the task is discarded.

BlockingQueue固定容量:

int fixedThreadNumber = 10;
int idleSeconds = 10;

BlockingQueue<Runnable> blockingQueue = new LinkedBlockingQueue<>(10);

ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
        fixedThreadNumber,
        fixedThreadNumber,
        idleSeconds, TimeUnit.SECONDS, 
        blockingQueue, new ThreadPoolExecutor.DiscardOldestPolicy());

ExecutorService executor = threadPoolExecutor;