Is there any way to set time limit for each request from queue into pool?
I have a class that inherits ThreadPoolExecutor
public class TaskPool extends ThreadPoolExecutor {
public TaskPool (int initialCountOfThreads, int maxPollSize) {
super(initialCountOfThreads, maxPollSize, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(150));
}
I'm adding tasks into thread pool
TaskPool taskPool = new TaskPool(2, 50);
for (int i = 0; i < 50000000; i++) {
task = new Task("Test" + i);
taskPool.execute(task);
}
And all the tasks that are in the queue are there until it is full, or rather, up to 150, and I want the tasks in the queue to be deleted after a some period of time if they are not included in the pool
com.company.example.TaskPool@2d6a9952[Running, pool size = 50, active threads = 48, queued tasks = 150, completed tasks = 7430]