/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
/** * Waits for N threads to enter the {@link #synchronize()} method, then * returns. * * @return * returns normally if N threads successfully synchronized. * @throws InterruptedException * if any of the threads that were synchronizing get interrupted, * or if the {@link #abort(Throwable)} is called. */ public synchronized void synchronize() throws InterruptedException { check(n); try { onCriteriaMet(); } catch (Error e) { abort(e); throw e; } catch (RuntimeException e) { abort(e); throw e; } check(n*2); }
/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
/** * When one of the work unit is aborted, call this method to abort all the * other work units. */ public synchronized void abort(Throwable cause) { if (cause == null) { throw new IllegalArgumentException(); } if (aborted != null) { return; // already aborted } aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e != null && e != c) { e.interrupt(); } } } }
/** * Waits for N threads to enter the {@link #synchronize()} method, then * returns. * * @return * returns normally if N threads successfully synchronized. * @throws InterruptedException * if any of the threads that were synchronizing get interrupted, * or if the {@link #abort(Throwable)} is called. */ public synchronized void synchronize() throws InterruptedException { check(n); try { onCriteriaMet(); } catch (Error e) { abort(e); throw e; } catch (RuntimeException e) { abort(e); throw e; } check(n*2); }