qudh1 opened SPR-17219 and commented
The CompletionService is basically a Queue which returns the Futures in the order which they complete.It would be better to use CompletionService to replace ExecutorSerive in the method org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.submit(Callable\
Current code is
@Override @Override public <T> Future<T> submit(Callable<T> task) { ExecutorService executor = getThreadPoolExecutor(); try { return executor.submit(task); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex); } }
Code implement by CompletionService is
@Override @Override public <T> Future<T> submit(Callable<T> task) { ExecutorService executor = getThreadPoolExecutor(); CompletionService<T> completionService = new ExecutorCompletionService<>(executor);
try { return completionService.submit(task); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex); } }
Affects: 5.0.8
Referenced from: pull request https://github.com/spring-projects/spring-framework/pull/1945
Comment From: snicoll
Duplicate of #1945