public class HashedWheelTimer extends Object implements Timer
HashedWheelTimer is based on
George Varghese and
Tony Lauck's paper,
'Hashed
and Hierarchical Timing Wheels: data structures to efficiently implement a
timer facility'. More comprehensive slides are located
here.
Forked from Netty.
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
WORKER_STATE_INIT |
static int |
WORKER_STATE_SHUTDOWN |
static int |
WORKER_STATE_STARTED |
| 构造器和说明 |
|---|
HashedWheelTimer()
Creates a new timer with the default thread factory
(
Executors.defaultThreadFactory()), default tick duration, and
default number of ticks per wheel. |
HashedWheelTimer(long tickDuration,
TimeUnit unit)
Creates a new timer with the default thread factory
(
Executors.defaultThreadFactory()) and default number of ticks
per wheel. |
HashedWheelTimer(long tickDuration,
TimeUnit unit,
int ticksPerWheel)
Creates a new timer with the default thread factory
(
Executors.defaultThreadFactory()). |
HashedWheelTimer(ThreadFactory threadFactory)
Creates a new timer with the default tick duration and default number of
ticks per wheel.
|
HashedWheelTimer(ThreadFactory threadFactory,
long tickDuration,
TimeUnit unit)
Creates a new timer with the default number of ticks per wheel.
|
HashedWheelTimer(ThreadFactory threadFactory,
long tickDuration,
TimeUnit unit,
int ticksPerWheel)
Creates a new timer.
|
HashedWheelTimer(ThreadFactory threadFactory,
long tickDuration,
TimeUnit unit,
int ticksPerWheel,
long maxPendingTimeouts)
Creates a new timer.
|
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
finalize() |
Timeout |
newTimeout(TimerTask task,
long delay,
TimeUnit unit)
Schedules the specified
TimerTask for one-time execution after
the specified delay. |
long |
pendingTimeouts()
Returns the number of pending timeouts of this
Timer. |
void |
start()
Starts the background thread explicitly.
|
Set<Timeout> |
stop()
Releases all resources acquired by this
Timer and cancels all
tasks which were scheduled but not executed yet. |
public static final int WORKER_STATE_INIT
public static final int WORKER_STATE_STARTED
public static final int WORKER_STATE_SHUTDOWN
public HashedWheelTimer()
Executors.defaultThreadFactory()), default tick duration, and
default number of ticks per wheel.public HashedWheelTimer(long tickDuration,
TimeUnit unit)
Executors.defaultThreadFactory()) and default number of ticks
per wheel.tickDuration - the duration between tickunit - the time unit of the tickDurationNullPointerException - if unit is nullIllegalArgumentException - if tickDuration is <= 0public HashedWheelTimer(long tickDuration,
TimeUnit unit,
int ticksPerWheel)
Executors.defaultThreadFactory()).tickDuration - the duration between tickunit - the time unit of the tickDurationticksPerWheel - the size of the wheelNullPointerException - if unit is nullIllegalArgumentException - if either of tickDuration and ticksPerWheel is <= 0public HashedWheelTimer(ThreadFactory threadFactory)
threadFactory - a ThreadFactory that creates a
background Thread which is dedicated to
TimerTask execution.NullPointerException - if threadFactory is nullpublic HashedWheelTimer(ThreadFactory threadFactory, long tickDuration, TimeUnit unit)
threadFactory - a ThreadFactory that creates a
background Thread which is dedicated to
TimerTask execution.tickDuration - the duration between tickunit - the time unit of the tickDurationNullPointerException - if either of threadFactory and unit is nullIllegalArgumentException - if tickDuration is <= 0public HashedWheelTimer(ThreadFactory threadFactory, long tickDuration, TimeUnit unit, int ticksPerWheel)
threadFactory - a ThreadFactory that creates a
background Thread which is dedicated to
TimerTask execution.tickDuration - the duration between tickunit - the time unit of the tickDurationticksPerWheel - the size of the wheelNullPointerException - if either of threadFactory and unit is nullIllegalArgumentException - if either of tickDuration and ticksPerWheel is <= 0public HashedWheelTimer(ThreadFactory threadFactory, long tickDuration, TimeUnit unit, int ticksPerWheel, long maxPendingTimeouts)
threadFactory - a ThreadFactory that creates a
background Thread which is dedicated to
TimerTask execution.tickDuration - the duration between tickunit - the time unit of the tickDurationticksPerWheel - the size of the wheelmaxPendingTimeouts - The maximum number of pending timeouts after which call to
newTimeout will result in
RejectedExecutionException
being thrown. No maximum pending timeouts limit is assumed if
this value is 0 or negative.NullPointerException - if either of threadFactory and unit is nullIllegalArgumentException - if either of tickDuration and ticksPerWheel is <= 0public void start()
IllegalStateException - if this timer has been
stopped alreadypublic Set<Timeout> stop()
TimerTimer and cancels all
tasks which were scheduled but not executed yet.public Timeout newTimeout(TimerTask task, long delay, TimeUnit unit)
TimerTimerTask for one-time execution after
the specified delay.newTimeout 在接口中 Timerpublic long pendingTimeouts()
Timer.Copyright © 2021. All rights reserved.