Java Code Examples for java.util.concurrent.ScheduledThreadPoolExecutor#submit()
The following examples show how to use
java.util.concurrent.ScheduledThreadPoolExecutor#submit() .
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: ScheduledExecutorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * A fixed delay task with overflowing period should not prevent a * one-shot task from executing. * https://bugs.openjdk.java.net/browse/JDK-8051859 */ public void testScheduleWithFixedDelay_overflow() throws Exception { final CountDownLatch delayedDone = new CountDownLatch(1); final CountDownLatch immediateDone = new CountDownLatch(1); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { final Runnable immediate = new Runnable() { public void run() { immediateDone.countDown(); }}; final Runnable delayed = new Runnable() { public void run() { delayedDone.countDown(); p.submit(immediate); }}; p.scheduleWithFixedDelay(delayed, 0L, Long.MAX_VALUE, SECONDS); await(delayedDone); await(immediateDone); } }
Example 2
Source File: ScheduledExecutorTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * A fixed delay task with overflowing period should not prevent a * one-shot task from executing. * https://bugs.openjdk.java.net/browse/JDK-8051859 */ public void testScheduleWithFixedDelay_overflow() throws Exception { final CountDownLatch delayedDone = new CountDownLatch(1); final CountDownLatch immediateDone = new CountDownLatch(1); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { final Runnable immediate = new Runnable() { public void run() { immediateDone.countDown(); }}; final Runnable delayed = new Runnable() { public void run() { delayedDone.countDown(); p.submit(immediate); }}; p.scheduleWithFixedDelay(delayed, 0L, Long.MAX_VALUE, SECONDS); await(delayedDone); await(immediateDone); } }
Example 3
Source File: AbstractVirtualHost.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Override public ListenableFuture<Void> reallocateMessages() { final ScheduledThreadPoolExecutor houseKeepingTaskExecutor = _houseKeepingTaskExecutor; if (houseKeepingTaskExecutor != null) { try { final Future<Void> future = houseKeepingTaskExecutor.submit(() -> { final Collection<Queue> queues = getChildren(Queue.class); for (Queue q : queues) { if (q.getState() == State.ACTIVE) { q.reallocateMessages(); } } return null; }); return JdkFutureAdapters.listenInPoolThread(future); } catch (RejectedExecutionException e) { if (!houseKeepingTaskExecutor.isShutdown()) { LOGGER.warn("Failed to schedule reallocation of messages", e); } } } return Futures.immediateFuture(null); }
Example 4
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(ScheduledThreadPoolExecutor service, Callable<T> callable, Runnable runnable, T value) { service.submit(callable); service.submit(runnable); service.submit(runnable, value); }