java.util.concurrent.AbstractExecutorService Java Examples
The following examples show how to use
java.util.concurrent.AbstractExecutorService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobRunnerTest.java From vespa with Apache License 2.0 | 6 votes |
private static ExecutorService phasedExecutor(Phaser phaser) { return new AbstractExecutorService() { final ExecutorService delegate = Executors.newFixedThreadPool(32); @Override public void shutdown() { delegate.shutdown(); } @Override public List<Runnable> shutdownNow() { return delegate.shutdownNow(); } @Override public boolean isShutdown() { return delegate.isShutdown(); } @Override public boolean isTerminated() { return delegate.isTerminated(); } @Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { return delegate.awaitTermination(timeout, unit); } @Override public void execute(Runnable command) { phaser.register(); delegate.execute(() -> { command.run(); phaser.arriveAndDeregister(); }); } }; }
Example #2
Source File: MockUpnpServiceConfiguration.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@Override protected ExecutorService getDefaultExecutorService() { if (isMultiThreaded()) { return super.getDefaultExecutorService(); } return new AbstractExecutorService() { boolean terminated; public void shutdown() { terminated = true; } public List<Runnable> shutdownNow() { shutdown(); return null; } public boolean isShutdown() { return terminated; } public boolean isTerminated() { return terminated; } public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException { shutdown(); return terminated; } public void execute(Runnable runnable) { runnable.run(); } }; }
Example #3
Source File: TaskExecutorCompletionService.java From tascalate-concurrent with Apache License 2.0 | 5 votes |
private static Executor wrapExecutor(Executor executor) { if (executor instanceof TaskExecutorService && executor instanceof AbstractExecutorService) { return executor; } else { return new GenericExecutorWrapper(executor); } }
Example #4
Source File: TestUtils.java From okta-sdk-appauth-android with Apache License 2.0 | 5 votes |
public static ExecutorService buildSyncynchronesExecutorService() { return new AbstractExecutorService() { @Override public void shutdown() { } @Override public List<Runnable> shutdownNow() { return null; } @Override public boolean isShutdown() { return false; } @Override public boolean isTerminated() { return false; } @Override public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException { return false; } @Override public void execute(Runnable runnable) { runnable.run(); } }; }
Example #5
Source File: JobRunnerTest.java From vespa with Apache License 2.0 | 5 votes |
public static ExecutorService inThreadExecutor() { return new AbstractExecutorService() { final AtomicBoolean shutDown = new AtomicBoolean(false); @Override public void shutdown() { shutDown.set(true); } @Override public List<Runnable> shutdownNow() { shutDown.set(true); return Collections.emptyList(); } @Override public boolean isShutdown() { return shutDown.get(); } @Override public boolean isTerminated() { return shutDown.get(); } @Override public boolean awaitTermination(long timeout, TimeUnit unit) { return true; } @Override public void execute(Runnable command) { command.run(); } }; }
Example #6
Source File: Ideas_2010_11_23.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@ExpectWarning("RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") public void test(AbstractExecutorService service, Callable<T> callable, Runnable runnable, T value) { service.submit(callable); service.submit(runnable); service.submit(runnable, value); }
Example #7
Source File: MockUpnpServiceConfiguration.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@Override protected ExecutorService getDefaultExecutorService() { if (isMultiThreaded()) { return super.getDefaultExecutorService(); } return new AbstractExecutorService() { boolean terminated; public void shutdown() { terminated = true; } public List<Runnable> shutdownNow() { shutdown(); return null; } public boolean isShutdown() { return terminated; } public boolean isTerminated() { return terminated; } public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException { shutdown(); return terminated; } public void execute(Runnable runnable) { runnable.run(); } }; }
Example #8
Source File: AsyncTestUtils.java From yelp-android with MIT License | 5 votes |
/** * Create an {@link ExecutorService} which runs jobs in main thread. */ public static ExecutorService newSynchronousExecutorService() { return new AbstractExecutorService() { @Override public void execute(Runnable command) { command.run(); } @Override public void shutdown() { throw new UnsupportedOperationException(); } @Override public List<Runnable> shutdownNow() { throw new UnsupportedOperationException(); } @Override public boolean isShutdown() { throw new UnsupportedOperationException(); } @Override public boolean isTerminated() { throw new UnsupportedOperationException(); } @Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { throw new UnsupportedOperationException(); } }; }
Example #9
Source File: LeaderSelector.java From xian with Apache License 2.0 | 4 votes |
private static ExecutorService wrapExecutor(final Executor executor) { return new AbstractExecutorService() { private volatile boolean isShutdown = false; private volatile boolean isTerminated = false; @Override public void shutdown() { isShutdown = true; } @Override public List<Runnable> shutdownNow() { return Lists.newArrayList(); } @Override public boolean isShutdown() { return isShutdown; } @Override public boolean isTerminated() { return isTerminated; } @Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { throw new UnsupportedOperationException(); } @Override public void execute(Runnable command) { try { executor.execute(command); } finally { isShutdown = true; isTerminated = true; } } }; }
Example #10
Source File: ExecutorServiceThreadPool.java From cyberduck with GNU General Public License v3.0 | 4 votes |
public ExecutorServiceThreadPool(final AbstractExecutorService pool) { this.pool = pool; }
Example #11
Source File: ExecutorServiceThreadPool.java From cyberduck with GNU General Public License v3.0 | 4 votes |
@Override public AbstractExecutorService executor() { return pool; }
Example #12
Source File: CheckJDKAnnotations.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
Future falsePositive(AbstractExecutorService e, Runnable r) { return e.submit(r, null); }
Example #13
Source File: ExecutorSchedulerTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Test public void failingExecutorServiceIsNotTerminated() { AtomicInteger count = new AtomicInteger(); final IllegalStateException boom = new IllegalStateException("boom"); ExecutorService service = new AbstractExecutorService() { boolean shutdown; @Override public void shutdown() { shutdown = true; } @NotNull @Override public List<Runnable> shutdownNow() { return Collections.emptyList(); } @Override public boolean isShutdown() { return shutdown; } @Override public boolean isTerminated() { return shutdown; } @Override public boolean awaitTermination(long timeout, @NotNull TimeUnit unit) throws InterruptedException { return false; } @Override public void execute(@NotNull Runnable command) { if (count.incrementAndGet() % 2 == 0) throw boom; } }; ExecutorScheduler scheduler = new ExecutorScheduler(service, false); assertThatCode(() -> scheduler.schedule(() -> {})) .as("initial-no rejection") .doesNotThrowAnyException(); assertThatExceptionOfType(RejectedExecutionException.class) .as("second-transient rejection") .isThrownBy(() -> scheduler.schedule(() -> {})) .withCause(boom); assertThatCode(() -> scheduler.schedule(() -> {})) .as("third-no rejection") .doesNotThrowAnyException(); assertThat(count.get()).isEqualTo(3); }
Example #14
Source File: ExecutorSchedulerTest.java From reactor-core with Apache License 2.0 | 4 votes |
@Test public void failingAndShutDownExecutorServiceIsTerminated() { final IllegalStateException boom = new IllegalStateException("boom"); ExecutorService service = new AbstractExecutorService() { boolean shutdown; @Override public void shutdown() { shutdown = true; } @NotNull @Override public List<Runnable> shutdownNow() { return Collections.emptyList(); } @Override public boolean isShutdown() { return shutdown; } @Override public boolean isTerminated() { return shutdown; } @Override public boolean awaitTermination(long timeout, @NotNull TimeUnit unit) throws InterruptedException { return false; } @Override public void execute(@NotNull Runnable command) { if (shutdown) throw boom; shutdown = true; } }; ExecutorScheduler scheduler = new ExecutorScheduler(service, false); assertThatCode(() -> scheduler.schedule(() -> {})) .as("initial-no rejection") .doesNotThrowAnyException(); assertThatExceptionOfType(RejectedExecutionException.class) .as("second-transient rejection") .isThrownBy(() -> scheduler.schedule(() -> {})) .withCause(boom); assertThatExceptionOfType(RejectedExecutionException.class) .as("third scheduler terminated rejection") .isThrownBy(() -> scheduler.schedule(() -> {})) .isSameAs(Exceptions.failWithRejected()) .withNoCause(); }
Example #15
Source File: LeaderSelector.java From curator with Apache License 2.0 | 4 votes |
private static ExecutorService wrapExecutor(final Executor executor) { return new AbstractExecutorService() { private volatile boolean isShutdown = false; private volatile boolean isTerminated = false; @Override public void shutdown() { isShutdown = true; } @Override public List<Runnable> shutdownNow() { return Lists.newArrayList(); } @Override public boolean isShutdown() { return isShutdown; } @Override public boolean isTerminated() { return isTerminated; } @Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { throw new UnsupportedOperationException(); } @Override public void execute(Runnable command) { try { executor.execute(command); } finally { isShutdown = true; isTerminated = true; } } }; }
Example #16
Source File: ThreadPool.java From cyberduck with GNU General Public License v3.0 | votes |
AbstractExecutorService executor();