Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CompletionService to replace ExecutorSerive in the method org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.submit(Callable<T>) [SPR-17219] #21752

Open
spring-projects-issues opened this issue Aug 27, 2018 · 0 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 27, 2018

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<T>).

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 #1945

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.