Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fork/Join kill siblings/branches

Tags:

java

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.

like image 395
Eric M Avatar asked Apr 17 '26 10:04

Eric M


1 Answers

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.

like image 100
edharned Avatar answered Apr 19 '26 23:04

edharned