@Override public Disposable schedule(Runnable task) { Objects.requireNonNull(task, "task"); if (terminated) { throw Exceptions.failWithRejected(); } ExecutorTrackedRunnable r = new ExecutorTrackedRunnable(task, this, false); synchronized (this) { if (terminated) { throw Exceptions.failWithRejected(); } queue.offer(r); } if (WIP.getAndIncrement(this) == 0) { try { executor.execute(this); } catch (Throwable ex) { r.dispose(); Schedulers.handleError(ex); throw Exceptions.failWithRejected(ex); } } return r; }
@Override public void run() { final Queue<ExecutorTrackedRunnable> q = queue; for (; ; ) { int e = 0; int r = wip; while (e != r) { if (terminated) { return; } ExecutorTrackedRunnable task = q.poll(); if (task == null) { break; } task.run(); e++; } if (e == r && terminated) { return; } if (WIP.addAndGet(this, -e) == 0) { break; } } }
@Override public void run() { final Queue<ExecutorTrackedRunnable> q = queue; for (; ; ) { int e = 0; int r = wip; while (e != r) { if (terminated) { return; } ExecutorTrackedRunnable task = q.poll(); if (task == null) { break; } task.run(); e++; } if (e == r && terminated) { return; } if (WIP.addAndGet(this, -e) == 0) { break; } } }
@Override public Disposable schedule(Runnable task) { Objects.requireNonNull(task, "task"); if (terminated) { throw Exceptions.failWithRejected(); } ExecutorTrackedRunnable r = new ExecutorTrackedRunnable(task, this, false); synchronized (this) { if (terminated) { throw Exceptions.failWithRejected(); } queue.offer(r); } if (WIP.getAndIncrement(this) == 0) { try { executor.execute(this); } catch (Throwable ex) { r.dispose(); Schedulers.handleError(ex); throw Exceptions.failWithRejected(ex); } } return r; }
@Override public Disposable schedule(Runnable task) { Objects.requireNonNull(task, "task"); ExecutorTrackedRunnable r = new ExecutorTrackedRunnable(task, this, true); if (!tasks.add(r)) { throw Exceptions.failWithRejected(); } try { executor.execute(r); } catch (Throwable ex) { tasks.remove(r); Schedulers.handleError(ex); throw Exceptions.failWithRejected(ex); } return r; }
@Override public void dispose() { if (compareAndSet(false, true)) { parent.delete(this); } }
@Override public void dispose() { if (terminated) { return; } terminated = true; final Queue<ExecutorTrackedRunnable> q = queue; ExecutorTrackedRunnable r; while ((r = q.poll()) != null && !q.isEmpty()) { r.dispose(); } }
@Override public boolean isDisposed() { return get(); } }
@Override public Disposable schedule(Runnable task) { Objects.requireNonNull(task, "task"); ExecutorTrackedRunnable r = new ExecutorTrackedRunnable(task, this, true); if (!tasks.add(r)) { throw Exceptions.failWithRejected(); } try { executor.execute(r); } catch (Throwable ex) { tasks.remove(r); Schedulers.handleError(ex); throw Exceptions.failWithRejected(ex); } return r; }
@Override public boolean isDisposed() { return get(); } }
@Override public void dispose() { if (compareAndSet(false, true)) { parent.delete(this); } }
@Override public void dispose() { if (terminated) { return; } terminated = true; final Queue<ExecutorTrackedRunnable> q = queue; ExecutorTrackedRunnable r; while ((r = q.poll()) != null && !q.isEmpty()) { r.dispose(); } }