-
-
Save lelodois/491efd378c44e08318deee07f7adef74 to your computer and use it in GitHub Desktop.
Using Executor Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.Executors; | |
public class MyTask { | |
private Callable<Boolean> createTask(Integer amount, MyTaskParam taskParam) { | |
return () -> taskParam.isAnyGreaterTo(amount); | |
} | |
public static void main(String[] args) throws InterruptedException { | |
Collection<Callable<Boolean>> tasks = new ArrayList<>(); | |
for (int i = 0; i < ; i++) { | |
Callable<Boolean> task = new MyTask().createTask(10, new MyTaskParam(i, new ArrayList<>())); | |
tasks.add(task); | |
} | |
Executors.newFixedThreadPool(20).invokeAll(tasks); | |
} | |
} | |
class MyTaskParam { | |
private Integer amount; | |
private List<MyTaskParam> children; | |
MyTaskParam(Integer amount, List<MyTaskParam> children) { | |
this.amount = amount; | |
this.children = children; | |
} | |
public Boolean isAnyGreaterTo(Integer otherAmount) { | |
if (amount > otherAmount) | |
for (MyTaskParam child : children) | |
return child.isAnyGreaterTo(otherAmount); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment