TL;DR version -
Is there a way to recursively create workers, then once you reach a certain number (or depth in the tree), have them perform some operation on the nodes below them? such as a search for a node?) I'm not sure I implemented mine correctly and so lost atmI'm trying to come up with a way to implement a tree search looking for a specific node.
My idea is that I can recursively create callables using the executorservice for the first two levels of the tree. After this point each worker will perform a search of their portion of the remaining tree and search for the node.
Is there a way to cap the number of workers created, while allowing workers already created to perform a search of their given subtrees?
I've tried using a fixedthread.pool but haven't I'm having trouble creating more than the first two sets of workers from the starting node of the tree.
Desperately in search of any help or tips, thanks!
Pretty much what my code looks like atm...
Code
public class Array[Node] findNode
public static ExecutorService ex = Executors.newFixedThreadPool(nThreads);
public findK(){
MyTask runnableObj = new MyTask(tree);
Future<Array<Node>> callFuture = ex.submit(runnableObj);
ex.shutdown();
try {
// Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
ex.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
try {
solution = callFuture.get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return solution;
}
class MyTask implements Callable<Array[Node]>{
public MyTask(Tree tree) {
super(tree);
// TODO Auto-generated constructor stub
}
public List<Direction> call() throws Exception {
....Trying to call this recursively so that I have a fixed number of workers searching subsections of the tree
..but not sure how to implement it
}
}
This post was edited by lopelurag on Apr 10 2014 08:19pm