I am using ThreadPoolExecutor as below:
ThreadPoolExecutor pool = new ThreadPoolExecutor(cores, 50, 30L,
TimeUnit.SECONDS, new ArrayBlockingQueue<>(10));
and :
pool.execute(()->{
//code goes here
if(some condition){
return;
}
//code goes here
})
And when this block with return statement is enabled, all those tasks gets stuck in TPE. TPE says that it's fully loaded and always throws RejectedExecutionExceptionexception
I can't understand why it happens. For example if you have a pool of size 10, and you have 100 tasks, 10 of them will match if section, you won't accept 101th task, all next tasks will be rejected. Why?