private Throwable waitFor(final AtomicReference<Throwable> reference) { while (reference.get() == null) { yield(); } return reference.get(); }
public SelectionKey take() throws IOException, InterruptedException { if (this.current == null || !this.current.hasNext()) { while (this.selector.select() == 0) { if (interrupted()) { throw new InterruptedException(); } yield(); } this.current = this.selector.selectedKeys().iterator(); assert this.current.hasNext(); } final SelectionKey key = this.current.next(); this.current.remove(); return key; }
private void assertProducerReaches( final StubPublisher stubPublisher, final int expectedPublicationCount, boolean strict) { long loopStart = System.currentTimeMillis(); while (stubPublisher.getPublicationCount() < expectedPublicationCount && System.currentTimeMillis() - loopStart < 5000) { yield(); } if (strict) { assertThat( Integer.valueOf(stubPublisher.getPublicationCount()), equalTo(Integer.valueOf(expectedPublicationCount))); } else { final int actualPublicationCount = stubPublisher.getPublicationCount(); assertTrue( "Producer reached unexpected count. Expected at least " + expectedPublicationCount + " but only reached " + actualPublicationCount, actualPublicationCount >= expectedPublicationCount); } }
void Delay() { for (int t = 0; t < 10000; t++) { Thread.yield(); } }