@Override public void run() { Thread.yield(); } },
public static void yield () { Thread.yield(); } }
public static void yield () { Thread.yield(); } }
@Override public Integer get() { int nextValue = counter + 1; Thread.yield(); counter = nextValue; return counter; } };
public void run() { Thread.yield(); pause(delay); _logMonitorFrame.setVisible(true); } });
public void run() { while (!shutdown.get()) { interruptee.interrupt(); Thread.yield(); } } });
static void awaitWaiting(Thread t) { while (true) { Thread.State state = t.getState(); switch (state) { case RUNNABLE: case BLOCKED: Thread.yield(); break; case WAITING: return; default: throw new AssertionError("unexpected state: " + state); } } }
/** Wait for the given thread to reach the {@link State#TIMED_WAITING} thread state. */ void awaitTimedWaiting(Thread thread) { while (true) { switch (thread.getState()) { case BLOCKED: case NEW: case RUNNABLE: case WAITING: Thread.yield(); break; case TIMED_WAITING: return; case TERMINATED: default: throw new AssertionError(); } } }
/** * Delays, via Thread.sleep, for the given millisecond delay, but if the sleep is shorter than * specified, may re-sleep or yield until time elapses. */ static void delay(long millis) throws InterruptedException { long startTime = System.nanoTime(); long ns = millis * 1000 * 1000; for (; ; ) { if (millis > 0L) Thread.sleep(millis); else // too short to sleep Thread.yield(); long d = ns - (System.nanoTime() - startTime); if (d > 0L) millis = d / (1000 * 1000); else break; } }
public void realRun() { while (!a.compareAndSet(0, 2.0, 3.0)) { Thread.yield(); } } });
public void realRun() { while (!at.compareAndSet(2.0, 3.0)) { Thread.yield(); } } });
void shutdown() { shutdown.set(true); while (this.isAlive()) { Thread.yield(); } } }
@Override public Boolean get() { // Check that this method is called exactly once, by the first // thread to synchronize. long t0 = System.nanoTime(); while (waitingThreads() != numThreads - 1) { if (System.nanoTime() - t0 > timeout) { thrown.set( new TimeoutException( "timed out waiting for other threads to block" + " synchronizing on supplier")); break; } Thread.yield(); } count.getAndIncrement(); return Boolean.TRUE; } };
void awaitWaiting() { while (!isBlocked()) { if (getState() == State.TERMINATED) { throw new RuntimeException("Thread exited"); } Thread.yield(); } }
void awaitWaiting() { while (!isBlocked()) { if (getState() == State.TERMINATED) { throw new RuntimeException("Thread exited"); } Thread.yield(); } }
private void assertUninterruptibleDrained(BlockingQueue<Object> q) { assertEquals(0, Queues.drainUninterruptibly(q, ImmutableList.of(), 0, 10, MILLISECONDS)); // but does the wait actually occurs? @SuppressWarnings("unused") // go/futurereturn-lsc Future<?> possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread())); Stopwatch timer = Stopwatch.createStarted(); Queues.drainUninterruptibly(q, newArrayList(), 1, 10, MILLISECONDS); assertThat(timer.elapsed(MILLISECONDS)).isAtLeast(10L); // wait for interrupted status and clear it while (!Thread.interrupted()) { Thread.yield(); } }
/** * Spin-waits up to the specified number of milliseconds for the given thread to enter a wait * state: BLOCKED, WAITING, or TIMED_WAITING. */ void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) { long startTime = System.nanoTime(); for (; ; ) { Thread.State s = thread.getState(); if (s == Thread.State.BLOCKED || s == Thread.State.WAITING || s == Thread.State.TIMED_WAITING) return; else if (s == Thread.State.TERMINATED) fail("Unexpected thread termination"); else if (millisElapsedSince(startTime) > timeoutMillis) { threadAssertTrue(thread.isAlive()); return; } Thread.yield(); } }
@Override public void subscribe(final Subscriber<? super Integer> subscriber) { BooleanSubscription bs = new BooleanSubscription(); subscriber.onSubscribe(bs); for (int i = 1; i <= 5; i++) { if (bs.isCancelled()) { break; } numEmitted.incrementAndGet(); subscriber.onNext(i); Thread.yield(); } subscriber.onComplete(); }
@Override public void subscribe(final Observer<? super Integer> o) { Disposable d = Disposables.empty(); o.onSubscribe(d); for (int i = 1; i <= 5; i++) { if (d.isDisposed()) { break; } numEmitted.incrementAndGet(); o.onNext(i); Thread.yield(); } o.onComplete(); }
@Test public void testHeartbeatThreadClose() throws Exception { ConsumerCoordinator coordinator = prepareCoordinatorForCloseTest(true, true, true); coordinator.ensureActiveGroup(); time.sleep(heartbeatIntervalMs + 100); Thread.yield(); // Give heartbeat thread a chance to attempt heartbeat closeVerifyTimeout(coordinator, Long.MAX_VALUE, requestTimeoutMs, requestTimeoutMs); Thread[] threads = new Thread[Thread.activeCount()]; int threadCount = Thread.enumerate(threads); for (int i = 0; i < threadCount; i++) assertFalse("Heartbeat thread active after close", threads[i].getName().contains(groupId)); }