APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.util.concurrent

pack-priv final Class DelayScheduler

extends Thread
Class Inheritance
Imports
java.util.Arrays, jdk.internal.misc.Unsafe

An add-on for ForkJoinPools that provides scheduling for delayed and periodic tasks

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
DelayScheduler.ScheduledForkJoinTask<T>

Task class for DelayScheduler operations

Field Summary

Modifier and TypeField and Description
pack-priv volatile int
private static final long
pack-priv volatile int
private static final int
pack-priv static final long
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv int
pack-priv volatile DelayScheduler.ScheduledForkJoinTask<?>
private static final long
pack-priv ForkJoinPool
private static final int
pack-priv int
private static final Unsafe
U

Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static void
pack-priv final void
cancelDelayedTasksOnShutdown()

Turns on cancelDelayedTasksOnShutdown policy

pack-priv final boolean
canShutDown()

Returns true if (momentarily) inactive and heap is empty

private static boolean
checkHeap(DelayScheduler.ScheduledForkJoinTask<?>[] h, int n)

Invariant checks

pack-priv final int
lastStableSize()

Returns the number of elements in heap when last idle

private void
loop(ForkJoinPool p)

After initialization, repeatedly: 1.

pack-priv static final long
now()

Returns System.nanoTime() with nanoTimeOffset

pack-priv final void
pend(DelayScheduler.ScheduledForkJoinTask<?> task)

Inserts the task (if nonnull) to pending queue, to add, remove, or ignore depending on task status when processed.

private static int

Returns:

current heap size
replace
(DelayScheduler.ScheduledForkJoinTask<?>[] h, int k, int n)

Replaces removed heap element at index k, along with other cancelled nodes found while doing so.

public final void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Sets up and runs scheduling loop

pack-priv final int
signal()

Ensures the scheduler is not parked unless stopped.

private int

Returns:

negative if stop, else current heap size.
tryStop
(ForkJoinPool p, DelayScheduler.ScheduledForkJoinTask<?>[] h, int n, int runStatus, int prevRunStatus)

Call only when pool run status is nonzero.

Inherited from java.lang.Thread:
activeCountcheckAccessclonecurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitsetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadthreadIdtoStringyield

Field Detail

activeback to summary
pack-priv volatile int active
ACTIVEback to summary
private static final long ACTIVE
cancelDelayedTasksOnShutdownback to summary
pack-priv volatile int cancelDelayedTasksOnShutdown
INITIAL_HEAP_CAPACITYback to summary
private static final int INITIAL_HEAP_CAPACITY
nanoTimeOffsetback to summary
pack-priv static final long nanoTimeOffset
pad0back to summary
pack-priv int pad0
pad1back to summary
pack-priv int pad1
pad2back to summary
pack-priv int pad2
pad3back to summary
pack-priv int pad3
pad4back to summary
pack-priv int pad4
pad5back to summary
pack-priv int pad5
pad6back to summary
pack-priv int pad6
pad7back to summary
pack-priv int pad7
pad8back to summary
pack-priv int pad8
pad9back to summary
pack-priv int pad9
padAback to summary
pack-priv int padA
padBback to summary
pack-priv int padB
padCback to summary
pack-priv int padC
padDback to summary
pack-priv int padD
padEback to summary
pack-priv int padE
pendingback to summary
pack-priv volatile DelayScheduler.ScheduledForkJoinTask<?> pending
PENDINGback to summary
private static final long PENDING
poolback to summary
pack-priv ForkJoinPool pool
POOL_STOPPINGback to summary
private static final int POOL_STOPPING
restingSizeback to summary
pack-priv int restingSize
Uback to summary
private static final Unsafe U

Constructor Detail

DelaySchedulerback to summary
pack-priv DelayScheduler(ForkJoinPool p, String name)

Method Detail

cancelAllback to summary
private static void cancelAll(DelayScheduler.ScheduledForkJoinTask<?>[] h, int n)
cancelDelayedTasksOnShutdownback to summary
pack-priv final void cancelDelayedTasksOnShutdown()

Turns on cancelDelayedTasksOnShutdown policy

canShutDownback to summary
pack-priv final boolean canShutDown()

Returns true if (momentarily) inactive and heap is empty

checkHeapback to summary
private static boolean checkHeap(DelayScheduler.ScheduledForkJoinTask<?>[] h, int n)

Invariant checks

lastStableSizeback to summary
pack-priv final int lastStableSize()

Returns the number of elements in heap when last idle

loopback to summary
private void loop(ForkJoinPool p)

After initialization, repeatedly: 1. If apparently no work, if active, set tentatively inactive, else park until next trigger time, or indefinitely if none 2. Process pending tasks in batches, to add or remove from heap 3. Check for shutdown, either exiting or preparing for shutdown when empty 4. Trigger all enabled tasks by submitting them to pool or run if immediate

nowback to summary
pack-priv static final long now()

Returns System.nanoTime() with nanoTimeOffset

pendback to summary
pack-priv final void pend(DelayScheduler.ScheduledForkJoinTask<?> task)

Inserts the task (if nonnull) to pending queue, to add, remove, or ignore depending on task status when processed.

replaceback to summary
private static int replace(DelayScheduler.ScheduledForkJoinTask<?>[] h, int k, int n)

Replaces removed heap element at index k, along with other cancelled nodes found while doing so.

Returns:int

current heap size

runback to summary
public final void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Sets up and runs scheduling loop

signalback to summary
pack-priv final int signal()

Ensures the scheduler is not parked unless stopped. Returns negative if already stopped

tryStopback to summary
private int tryStop(ForkJoinPool p, DelayScheduler.ScheduledForkJoinTask<?>[] h, int n, int runStatus, int prevRunStatus)

Call only when pool run status is nonzero. Possibly cancels tasks and stops during pool shutdown and termination. If called when shutdown but not stopping, removes tasks according to policy if not already done so, and if not empty or pool not terminating, returns. Otherwise, cancels all tasks in heap and pending queue.

Returns:int

negative if stop, else current heap size.

java.util.concurrent back to summary

pack-priv final Class DelayScheduler.ScheduledForkJoinTask<T>

extends ForkJoinTask.InterruptibleTask<T>
implements ScheduledFuture<T>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.ScheduledFuture, java.util.concurrent.Future, java.util.concurrent.Delayed, java.lang.Comparable
Annotations
@SuppressWarnings:serial

Task class for DelayScheduler operations

Field Summary

Modifier and TypeField and Description
pack-priv Callable<? extends T>
pack-priv int
pack-priv final boolean
pack-priv final long
pack-priv DelayScheduler.ScheduledForkJoinTask<?>
pack-priv ForkJoinPool
pack-priv T
pack-priv Runnable
pack-priv long
Inherited from java.util.concurrent.ForkJoinTask.InterruptibleTask:
runner

Constructor Summary

AccessConstructor and Description
public
ScheduledForkJoinTask(long
initial delay, in nanoseconds
delay
,
long
0 for one-shot, negative for fixed delay, positive for fixed rate, in nanoseconds
nextDelay
,
boolean
if action is to be performed by scheduler versus submitting to a WorkQueue
isImmediate
,
Runnable
action (null if implementing callable version)
runnable
,
Callable<T>
function (null if implementing runnable versions)
callable
,
ForkJoinPool
the pool for resubmissions and cancellations (disabled if null)
pool
)

Creates a new ScheduledForkJoinTask

Method Summary

Modifier and TypeMethod and Description
pack-priv final Object
public final boolean
cancel(boolean mayInterruptIfRunning)

Overrides java.util.concurrent.ForkJoinTask.InterruptibleTask.cancel.

Implements java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task.

public int
compareTo(Delayed other)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

pack-priv final T
public final long
getDelay(TimeUnit unit)

Implements java.util.concurrent.Delayed.getDelay.

Returns the remaining delay associated with this object, in the given time unit.

public final T
getRawResult()

Implements abstract java.util.concurrent.ForkJoinTask.getRawResult.

Returns the result that would be returned by join, even if this task completed abnormally, or null if this task is not known to have been completed.

pack-priv final boolean
public void
public final void
setRawResult(T v)

Implements abstract java.util.concurrent.ForkJoinTask.setRawResult.

Forces the given value to be returned as a result.

Inherited from java.util.concurrent.ForkJoinTask.InterruptibleTask:
execinterruptIfRunningruntoString

Field Detail

callableback to summary
pack-priv Callable<? extends T> callable
heapIndexback to summary
pack-priv int heapIndex
isImmediateback to summary
pack-priv final boolean isImmediate
nextDelayback to summary
pack-priv final long nextDelay
nextPendingback to summary
pack-priv DelayScheduler.ScheduledForkJoinTask<?> nextPending
poolback to summary
pack-priv ForkJoinPool pool
resultback to summary
pack-priv T result
runnableback to summary
pack-priv Runnable runnable
whenback to summary
pack-priv long when

Constructor Detail

ScheduledForkJoinTaskback to summary
public ScheduledForkJoinTask(long delay, long nextDelay, boolean isImmediate, Runnable runnable, Callable<T> callable, ForkJoinPool pool)

Creates a new ScheduledForkJoinTask

Parameters
delay:long

initial delay, in nanoseconds

nextDelay:long

0 for one-shot, negative for fixed delay, positive for fixed rate, in nanoseconds

isImmediate:boolean

if action is to be performed by scheduler versus submitting to a WorkQueue

runnable:Runnable

action (null if implementing callable version)

callable:Callable<T>

function (null if implementing runnable versions)

pool:ForkJoinPool

the pool for resubmissions and cancellations (disabled if null)

Method Detail

adapteeback to summary
pack-priv final Object adaptee()

Overrides java.util.concurrent.ForkJoinTask.InterruptibleTask.adaptee.

cancelback to summary
public final boolean cancel(boolean mayInterruptIfRunning)

Overrides java.util.concurrent.ForkJoinTask.InterruptibleTask.cancel.

Implements java.util.concurrent.Future.cancel.

Doc from java.util.concurrent.Future.cancel.

Attempts to cancel execution of this task. This method has no effect if the task is already completed or cancelled, or could not be cancelled for some other reason. Otherwise, if this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task (when known by the implementation) is interrupted in an attempt to stop the task.

The return value from this method does not necessarily indicate whether the task is now cancelled; use isCancelled.

compareToback to summary
public int compareTo(Delayed other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

computeback to summary
pack-priv final T compute() throws Exception

Implements abstract java.util.concurrent.ForkJoinTask.InterruptibleTask.compute.

getDelayback to summary
public final long getDelay(TimeUnit unit)

Implements java.util.concurrent.Delayed.getDelay.

Doc from java.util.concurrent.Delayed.getDelay.

Returns the remaining delay associated with this object, in the given time unit.

getRawResultback to summary
public final T getRawResult()

Implements abstract java.util.concurrent.ForkJoinTask.getRawResult.

Doc from java.util.concurrent.ForkJoinTask.getRawResult.

Returns the result that would be returned by join, even if this task completed abnormally, or null if this task is not known to have been completed. This method is designed to aid debugging, as well as to support extensions. Its use in any other context is discouraged.

postExecback to summary
pack-priv final boolean postExec()

Overrides java.util.concurrent.ForkJoinTask.InterruptibleTask.postExec.

scheduleback to summary
public void schedule()
setRawResultback to summary
public final void setRawResult(T v)

Implements abstract java.util.concurrent.ForkJoinTask.setRawResult.

Doc from java.util.concurrent.ForkJoinTask.setRawResult.

Forces the given value to be returned as a result. This method is designed to support extensions, and should not in general be called otherwise.