public JobHandle submit( Group group, Runnable job, long initialDelayNanos, long reschedulingDelayNanos ) { long now = clock.nanos(); long nextDeadlineNanos = now + initialDelayNanos; ScheduledJobHandle task = new ScheduledJobHandle( this, group, job, nextDeadlineNanos, reschedulingDelayNanos ); enqueueTask( task ); return task; }
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 ); } }; }
public JobHandle submit( Group group, Runnable job, long initialDelayNanos, long reschedulingDelayNanos ) { long now = clock.nanos(); long nextDeadlineNanos = now + initialDelayNanos; ScheduledJobHandle task = new ScheduledJobHandle( this, group, job, nextDeadlineNanos, reschedulingDelayNanos ); enqueueTask( task ); return task; }
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 ); } }; }