You should be able to accomplish this by creating your own class that extends ThreadPoolExecutor
and providing your own shutdown method.
Below is an example for how this could be done, you might want to adjust it to your needs (providing more constructor methods for example)
public class MyExecutor extends ThreadPoolExecutor {
private final BlockingQueue<Runnable> queue;
public MyExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
this.queue = workQueue;
}
public List<Runnable> shutdownSpecial() {
ArrayList<Runnable> queued = new ArrayList<>();
queue.drainTo(queued);
this.shutdown();
return queued;
}
}