Waits for completion of all Callable s corresponding to the Future s given. If the current thread is interrupted, each of the Callable s gets cancelled and interrupted. Also in that case, this method waits until all callables have finished. The 'interrupted'
(Future[] futures)
| 126 | * as required for preview in an ImageJ ExtendedPlugInFilter. |
| 127 | */ |
| 128 | public static void joinAll(Future[] futures) { |
| 129 | boolean interrupted = false; |
| 130 | for (int i=0; i<futures.length; i++) { |
| 131 | Future f = futures[i]; |
| 132 | try { |
| 133 | f.get(); |
| 134 | } catch (InterruptedException e) { |
| 135 | interrupted = true; |
| 136 | for (int j=i; j<futures.length; j++) |
| 137 | futures[j].cancel(true); |
| 138 | i--; //we still have to wait for completion of this one |
| 139 | } catch (CancellationException e) { //cancellation is allowed, e.g. during preview |
| 140 | } catch (Exception eOther) { |
| 141 | ij.IJ.log("Error in thread called by "+Thread.currentThread().getName()+":\n"+eOther); |
| 142 | } |
| 143 | } |
| 144 | if (interrupted) { |
| 145 | Thread.currentThread().interrupt(); |
| 146 | threadPoolExecutor.purge(); |
| 147 | } |
| 148 | } |
| 149 | } |
no test coverage detected