I'm using Fork/Join to recursively search for a solution to a problem.
/——----1------\
/--1.1--\ /--1.2--\
1.1.1 1.1.2 1.2.1 1.2.2
Now lets say I find the solution in 1.2.1. Is there a way to cancel all other process in the forkjoin pool?
Whatabout if I know that 1.1 and 1.2 each contain a potential solution - so I only want to cancel my siblings (and any sub forks they may have spawned)?
I could used some shared object flag, but I hoped Fork/Join had a cleaner way to kill off branches or siblings.
No. Once started it goes to completion or Error/Exception.
You would have to program a cancel yourself. That is, pass a volatile boolean to each Task, when ready set the boolean to true (cancel). Each Task can test the boolean for true and just stop immediately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With