类 Schedule

java.lang.Object
io.github.vipcxj.schedule.Schedule
所有已实现的接口:
Closeable, AutoCloseable

public class Schedule extends Object implements Closeable
High-performance schedule manager
  • 构造器详细资料

    • Schedule

      public Schedule()
  • 方法详细资料

    • instance

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

      public void close()
      指定者:
      close 在接口中 AutoCloseable
      指定者:
      close 在接口中 Closeable
    • 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<DisposableImpl, EventHandle> 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.