I have 1000 big files to be processed in order as mentioned below:
- First those files needs to be copied to a different directory in parallel, I am planning to use
ExecutorService
with 10 threads to achieve it. - As soon as any file is copied to another location(#1), I will submit that file for further processing to
ExecutorService
with 10 threads. - And finally, another action needs to be performed on these files in parallel, like #2 gets input from #1, #3 gets input from #2.
Now, I can use CompletionService
here, so I can process the thread results from #1 to #2 and #2 to #3 in the order they are getting completed. CompletableFuture
says we can chain asynchronous tasks together which sounds like something I can use in this case.
I am not sure if I should implement my solution with CompletableFuture
(since it is relatively new and ought to be better) or if CompletionService
is sufficient? And why should I chose one over another in this case?