类 Schedule
- java.lang.Object
-
- io.github.vipcxj.schedule.Schedule
-
- 所有已实现的接口:
Closeable,AutoCloseable
public class Schedule extends Object implements Closeable
High-performance schedule manager
-
-
构造器概要
构造器 构造器 说明 Schedule()
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 EventHandleaddEvent(long nanoTime, Runnable callback)schedule the callbackEventHandleaddEvent(long time, TimeUnit unit, Runnable callback)schedule the callbackvoidclose()static EventHandlecreateInvalidHandle()Used for CAS.static Scheduleinstance()Get the singleton instance.
-
-
-
方法详细资料
-
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 AtomicReferenceFieldUpdaterHANDLE = 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.
-
-