Java - Task polling example with Java 8

less than 1 minute read

1
2
3
4
5
6
7
8
9
10
11
public void completionService(ExecutorService executor) {
    CompletionService<CustomTaskResult> completionService =
        new ExecutorCompletionService<CustomTaskResult>(executor);
    completionService.submit(() => {
        // to something
    });
    Future<CustomTaskResult> future = null
    while ((future = completionService.poll()) != null) {
    	// do something
    }
}