@Test void releaseThenAwaitDoesNotBlock() { assertTimeout( ofSeconds( 3 ), () -> { BinaryLatch latch = new BinaryLatch(); latch.release(); latch.await(); } ); }
public void awaitUpdateApplication() { BinaryLatch updateLatch = new BinaryLatch(); scheduler.schedule( Group.INDEX_UPDATING, updateLatch::release ); updateLatch.await(); } }
@Override public void release() { latchMap.setLatch( index, null ); super.release(); } }
@Test void releaseMustUnblockAwaiters() { assertTimeout( ofSeconds( 10 ), () -> { final BinaryLatch latch = new BinaryLatch(); Runnable awaiter = latch::await; int awaiters = 24; Future<?>[] futures = new Future<?>[awaiters]; for ( int i = 0; i < awaiters; i++ ) { futures[i] = executor.submit( awaiter ); } assertThrows( TimeoutException.class, () -> futures[0].get( 10, TimeUnit.MILLISECONDS ) ); latch.release(); for ( Future<?> future : futures ) { future.get(); } } ); }
public void awaitStartup() { startupLatch.await(); }
/** * Construct a new {@code AsyncEvents} instance, that will use the given consumer to process the events. * * @param eventConsumer The {@link Consumer} used for processing the events that are sent in. */ public AsyncEvents( Consumer<T> eventConsumer, Monitor monitor ) { this.eventConsumer = eventConsumer; this.monitor = monitor; this.startupLatch = new BinaryLatch(); this.shutdownLatch = new BinaryLatch(); this.stack = END_SENTINEL; }
unparkAll( others ); while ( !isReleased( waiter ) );
public void unlock( int recordId ) { map.remove( recordId ).release(); } }
@Test public void longRunningTasksMustNotDelayExecutionOfOtherTasks() throws Exception { BinaryLatch latch = new BinaryLatch(); Runnable longRunning = latch::await; Runnable shortRunning = semaphore::release; scheduler.submit( Group.STORAGE_MAINTENANCE, longRunning, 100, 100 ); scheduler.submit( Group.STORAGE_MAINTENANCE, shortRunning, 100, 100 ); for ( int i = 0; i < 4; i++ ) { clock.forward( 100, TimeUnit.NANOSECONDS ); scheduler.tick(); assertSemaphoreAcquire(); } latch.release(); }
public void awaitTermination() { shutdownLatch.await(); }
public void lock( int recordId ) { Integer record = recordId; BinaryLatch myLatch = new BinaryLatch(); for (;;) { BinaryLatch existingLatch = map.putIfAbsent( record, myLatch ); if ( existingLatch == null ) { break; } else { existingLatch.await(); } } }
public boolean tryLock( int recordId ) { Integer record = recordId; BinaryLatch myLatch = new BinaryLatch(); BinaryLatch existingLatch = map.putIfAbsent( record, myLatch ); return existingLatch == null; }
unparkAll( others ); while ( !isReleased( waiter ) );
final AtomicReference<BinaryLatch> latchRef = new AtomicReference<>( new BinaryLatch() ); Runnable awaiter = () -> while ( (latch = latchRef.get()) != null ) latch.await(); for ( int i = 0; i < 500000; i++ ) latchRef.getAndSet( new BinaryLatch() ).release(); spin( rng.nextLong( 0, 10 ) ); latchRef.getAndSet( null ).release();
@Override public void run() { try { while ( !halted ) { try { pageCache.flushAndForce(); } catch ( Throwable e ) { error = e; break; } } } finally { halt.release(); } }
BinaryLatch indexUpdateBlocker = new BinaryLatch(); db.getDependencyResolver().resolveDependency( JobScheduler.class, ONLY ).schedule( Group.INDEX_UPDATING, indexUpdateBlocker::await ); indexUpdateBlocker.release();
/** * Halts this flusher, making it stop flushing. The current call to {@link PageCache#flushAndForce()} * will complete before exiting this method call. If there was an error in the thread doing the flushes * that exception will be thrown from this method as a {@link RuntimeException}. */ void halt() { halted = true; halt.await(); if ( error != null ) { throwIfUnchecked( error ); throw new RuntimeException( error ); } } }
ScheduledJobHandle( TimeBasedTaskScheduler scheduler, Group group, Runnable task, long nextDeadlineNanos, long reschedulingDelayNanos ) { this.group = group; this.nextDeadlineNanos = nextDeadlineNanos; handleRelease = new BinaryLatch(); cancelListeners = new CopyOnWriteArrayList<>(); this.task = () -> { try { task.run(); // Use compareAndSet to avoid overriding any cancellation state. if ( compareAndSet( SUBMITTED, RUNNABLE ) && reschedulingDelayNanos > 0 ) { // We only reschedule if the rescheduling delay is greater than zero. // A rescheduling delay of zero means this is a delayed task. // If the rescheduling delay is greater than zero, then this is a recurring task. this.nextDeadlineNanos += reschedulingDelayNanos; scheduler.enqueueTask( this ); } } catch ( Throwable e ) { lastException = e; set( FAILED ); } }; }