void writeSynResetLater(final int streamId, final ErrorCode errorCode) { try { writerExecutor.execute(new NamedRunnable("OkHttp %s stream %d", connectionName, streamId) { @Override public void execute() { try { writeSynReset(streamId, errorCode); } catch (IOException e) { failConnection(); } } }); } catch (RejectedExecutionException ignored) { // This connection has been closed. } }
void writeWindowUpdateLater(final int streamId, final long unacknowledgedBytesRead) { try { writerExecutor.execute( new NamedRunnable("OkHttp Window Update %s stream %d", connectionName, streamId) { @Override public void execute() { try { writer.windowUpdate(streamId, unacknowledgedBytesRead); } catch (IOException e) { failConnection(); } } }); } catch (RejectedExecutionException ignored) { // This connection has been closed. } }
private void runWriter() { assert (Thread.holdsLock(this)); if (executor != null) { executor.execute(writerRunnable); } }
@Override public void execute(Runnable command) { delegate.execute(command); } }
public static void onActivityCreated(Activity activity) { singleThreadExecutor.execute(new Runnable() { @Override public void run() { if (currentSession == null) { currentSession = SessionInfo.getStoredSessionInfo(); } } }); }
private void runWriter() { assert (Thread.holdsLock(this)); if (executor != null) { executor.execute(writerRunnable); } }
@Override public void nodeViewInitialized() { if (!initialized.getAndSet(true)) { executor.execute(HttpServerInventoryView.this::serverInventoryInitialized); } }
@Override protected final void doStop() { runningTask.cancel(false); executorService.execute( new Runnable() { @Override public void run() { try { lock.lock(); try { if (state() != State.STOPPING) { // This means that the state has changed since we were scheduled. This implies // that an execution of runOneIteration has thrown an exception and we have // transitioned to a failed state, also this means that shutDown has already // been called, so we do not want to call it again. return; } shutDown(); } finally { lock.unlock(); } notifyStopped(); } catch (Throwable t) { notifyFailed(t); } } }); }
private synchronized void notifyBlockedCallers() { List<SettableFuture<?>> callers = ImmutableList.copyOf(blockedCallers); blockedCallers.clear(); for (SettableFuture<?> blockedCaller : callers) { // Notify callers in a separate thread to avoid callbacks while holding a lock scheduler.execute(() -> blockedCaller.set(null)); } }
@Override public void set(String key, String value, int expireTime) { cache.put(key, value); executor.execute(this::writeToFile); }
private void applyAndAckSettings(final Settings peerSettings) { try { writerExecutor.execute(new NamedRunnable("OkHttp %s ACK Settings", connectionName) { @Override public void execute() { try { writer.applyAndAckSettings(peerSettings); } catch (IOException e) { failConnection(); } } }); } catch (RejectedExecutionException ignored) { // This connection has been closed. } }
@Override public void ping(boolean reply, int payload1, int payload2) { if (reply) { synchronized (Http2Connection.this) { awaitingPong = false; Http2Connection.this.notifyAll(); } } else { try { // Send a reply to a client ping if this is a server and vice versa. writerExecutor.execute(new PingRunnable(true, payload1, payload2)); } catch (RejectedExecutionException ignored) { // This connection has been closed. } } }
@Override public long hincrBy(String key, String field, long value) { Map fields = ((Map) cache.computeIfAbsent(key, k -> new ConcurrentHashMap<>())); Number num = (Number) fields.get(field); long result = num.longValue() + 1; fields.put(field, result); executor.execute(this::writeToFile); return result; }
/** * Clean up resources. */ @Override public void destroyResources() { if (eurekaConnCleaner != null) { // Execute the connection cleaner one final time during shutdown eurekaConnCleaner.execute(connectionCleanerTask); eurekaConnCleaner.shutdown(); } if (apacheHttpClient != null) { apacheHttpClient.close(); } }
private void scheduleRevoking() { taskManagementExecutor.execute(() -> { try { runMemoryRevoking(); } catch (Throwable e) { log.error(e, "Error requesting memory revoking"); } }); }
executorService.execute( new Runnable() { @Override
@Override public void onEvent(Event event) { if (isFixedPolling()) { // ignore } else { if (event instanceof LocalDataChangeEvent) { LocalDataChangeEvent evt = (LocalDataChangeEvent)event; scheduler.execute(new DataChangeTask(evt.groupKey, evt.isBeta, evt.betaIps)); } } }
public void testGetExitingScheduledExecutorService_executorDelegatesToOriginal() { TestApplication application = new TestApplication(); ScheduledThreadPoolExecutor executor = mock(ScheduledThreadPoolExecutor.class); ThreadFactory threadFactory = mock(ThreadFactory.class); when(executor.getThreadFactory()).thenReturn(threadFactory); application.getExitingScheduledExecutorService(executor).execute(EMPTY_RUNNABLE); verify(executor).execute(EMPTY_RUNNABLE); }
/** * {@inheritDoc} */ public final void start() { if (isStarted()) return; if (getContext() == null) { throw new IllegalStateException("context not set"); } if (shouldStart()) { getContext().getScheduledExecutorService().execute(getRunnableTask()); started = true; } }
@GwtIncompatible // threads public void testScheduleAsync_asyncCallable_cancelledBeforeCallingFunction() throws InterruptedException { final AtomicBoolean callableCalled = new AtomicBoolean(); AsyncCallable<Integer> callable = new AsyncCallable<Integer>() { @Override public ListenableFuture<Integer> call() { callableCalled.set(true); return immediateFuture(1); } }; ScheduledExecutorService executor = newSingleThreadScheduledExecutor(); // Pause the executor. final CountDownLatch beforeFunction = new CountDownLatch(1); executor.execute( new Runnable() { @Override public void run() { awaitUninterruptibly(beforeFunction); } }); ListenableFuture<Integer> future = scheduleAsync(callable, 1, TimeUnit.NANOSECONDS, executor); future.cancel(false); // Unpause the executor. beforeFunction.countDown(); executor.shutdown(); assertTrue(executor.awaitTermination(5, SECONDS)); assertFalse(callableCalled.get()); }