类 Schedule

    • 构造器详细资料

      • Schedule

        public Schedule()
    • 方法详细资料

      • instance

        public static Schedule instance()
        Get the singleton instance.
        返回:
        singleton instance
      • createInvalidHandle

        public static EventHandle createInvalidHandle()
        Used for CAS. For example:
             static class DisposableImpl implements JDisposable {
        
                 // Create a handle placeholder representing invalid handle.
                 private static final EventHandle INVALID = Schedule.createInvalidHandle();
                 private volatile EventHandle handle;
                 private static final AtomicReferenceFieldUpdater HANDLE
                         = AtomicReferenceFieldUpdater.newUpdater(DisposableImpl.class, EventHandle.class, "handle");
        
                 void updateHandle(EventHandle newHandle) {
                     while (true) {
                         EventHandle handle = this.handle;
                         if (handle == INVALID || HANDLE.weakCompareAndSet(this, handle, newHandle)) {
                             return;
                         }
                     }
                 }
        
                 public void dispose() {
                     while (true) {
                         EventHandle handle = this.handle;
                         if (handle == INVALID) {
                             return;
                         }
                         if (HANDLE.weakCompareAndSet(this, handle, INVALID)) {
                             handle.remove();
                             return;
                         }
                     }
                 }
        
                 public boolean isDisposed() {
                     return handle == INVALID;
                 }
             }
         
        返回:
        a invalid handle.
      • addEvent

        public EventHandle addEvent​(long time,
                                    TimeUnit unit,
                                    Runnable callback)
        schedule the callback
        参数:
        time - the time when the callback invoked.
        unit - the time unit.
        callback - the callback.
      • addEvent

        public EventHandle addEvent​(long nanoTime,
                                    Runnable callback)
        schedule the callback
        参数:
        nanoTime - the time in nanoseconds when the callback invoked.
        callback - the callback.