| Modifier and Type | Class and Description |
|---|---|
| private static class | VirtualThread.
Supports scheduling a runnable task to run after a delay. |
| private static class | VirtualThread.
The continuation that a virtual thread executes. |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private static final int | |
| private volatile boolean | |
| private static final long | |
| private volatile Thread | |
| private final Continuation | cont
Hides java. |
| private static final ForkJoinPool | |
| private volatile boolean | |
| private static final int | |
| private volatile VirtualThread | |
| private volatile boolean | |
| private volatile boolean | |
| private static final long | |
| private volatile boolean | |
| private static final long | |
| private static final int | |
| private static final int | |
| private volatile boolean | |
| private static final int | |
| private final Runnable | |
| private static final int | |
| private final Executor | |
| private static final int | |
| private static final long | |
| private volatile int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private byte | |
| private long | |
| private Future | |
| private static final Unsafe | |
| private static final int | |
| private static final int | |
| private static final ContinuationScope | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| pack-priv | VirtualThread(Executor
the scheduler or null scheduler, String thread name name, int characteristics characteristics, Runnable the task to execute task)Creates a new |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | afterDone(boolean
true if its container should be notified notifyContainer)Invoked after the continuation completes (or start failed). |
| private void | afterYield()
Invoked in the context of the carrier thread after the Continuation yields when parking, blocking on monitor enter, Object.wait, or Thread.yield. |
| pack-priv boolean | |
| private boolean | Returns: true if mounted, false if not mountedAppends the carrier state and thread name to the string buffer if mounted. |
| pack-priv void | |
| pack-priv void | |
| private void | |
| private Object | |
| private boolean | |
| private boolean | |
| pack-priv static ContinuationScope | |
| private static ForkJoinPool | |
| pack-priv static Executor | |
| private void | |
| private void | |
| private native void | |
| private native void | |
| public boolean | equals(Object obj)
Overrides java. Indicates whether some other object is "equal to" this one. |
| private void | externalSubmitRunContinuation(ForkJoinPool pool)
Submits the runContinuation task to the given scheduler as an external submit. |
| private void | |
| pack-priv boolean | |
| private boolean | |
| public int | |
| public void | |
| public boolean | isInterrupted()
Overrides java. Tests whether this thread has been interrupted. |
| pack-priv boolean | |
| private void | lazySubmitRunContinuation()
Lazy submit the runContinuation task if invoked on a carrier thread and its local queue is empty. |
| private void | |
| private static native void | |
| pack-priv void | |
| pack-priv void | parkNanos(long
the maximum number of nanoseconds to wait. nanos)Implements abstract java. Parks up to the given waiting time or until unparked or interrupted. |
| private void | parkOnCarrierThread(boolean
true for a timed park, false for untimed timed, long the waiting time in nanoseconds nanos)Parks the current carrier thread up to the given waiting time or until unparked or interrupted. |
| private void | |
| private static native void | |
| private static native void | |
| private void | |
| public void | run()
Overrides java. Implements java. This method is run by the thread when it executes. |
| private void | |
| private Future | |
| private void | |
| private void | |
| private void | |
| pack-priv void | sleepNanos(long
the maximum number of nanoseconds to sleep nanos)Hides java. Sleep the current thread for the given sleep time (in nanoseconds). |
| pack-priv void | start(ThreadContainer container)
Overrides java. Schedules this |
| public void | |
| private native void | |
| private native void | |
| private int | |
| private void | |
| private void | |
| private void | submitRunContinuation(Executor
the scheduler scheduler, boolean true to retry indefinitely if OutOfMemoryError is thrown retryOnOOME)Submits the runContinuation task to the scheduler. |
| private void | |
| private static native VirtualThread | takeVirtualThreadListToUnblock()
Retrieves the list of virtual threads that are waiting to be unblocked, waiting if necessary until a list of one or more threads becomes available. |
| pack-priv Thread. | |
| private Object | |
| public String | |
| pack-priv void | |
| private void | |
| private static void | unblockVirtualThreads()
Schedule virtual threads that are ready to be scheduled after they blocked on monitor enter. |
| private void | |
| private void | unpark(boolean
to use lazySubmit if possible lazySubmit)Re-enables this virtual thread for scheduling. |
| pack-priv void | unpark()
Implements abstract java. Makes available the parking permit to the given this virtual thread. |
| private void | waitTimeoutExpired(byte seqNo)
Invoked by FJP worker thread or STPE thread when wait timeout expires. |
| private boolean | yieldContinuation()
Invokes Continuation.yield, notifying JVMTI (if enabled) to hide frames until the continuation continues. |
| BLOCKED | back to summary |
|---|---|
| private static final int BLOCKED | |
| BLOCKING | back to summary |
|---|---|
| private static final int BLOCKING | |
| blockPermit | back to summary |
|---|---|
| private volatile boolean blockPermit | |
| CARRIER_THREAD | back to summary |
|---|---|
| private static final long CARRIER_THREAD | |
| carrierThread | back to summary |
|---|---|
| private volatile Thread carrierThread | |
| cont | back to summary |
|---|---|
| private final Continuation cont Hides java. | |
| DEFAULT_SCHEDULER | back to summary |
|---|---|
| private static final ForkJoinPool DEFAULT_SCHEDULER | |
| interruptibleWait | back to summary |
|---|---|
| private volatile boolean interruptibleWait | |
| NEW | back to summary |
|---|---|
| private static final int NEW | |
| next | back to summary |
|---|---|
| private volatile VirtualThread next | |
| notified | back to summary |
|---|---|
| private volatile boolean notified | |
| notifyAllAfterTerminate | back to summary |
|---|---|
| private volatile boolean notifyAllAfterTerminate | |
| ON_WAITING_LIST | back to summary |
|---|---|
| private static final long ON_WAITING_LIST | |
| onWaitingList | back to summary |
|---|---|
| private volatile boolean onWaitingList | |
| PARK_PERMIT | back to summary |
|---|---|
| private static final long PARK_PERMIT | |
| PARKED | back to summary |
|---|---|
| private static final int PARKED | |
| PARKING | back to summary |
|---|---|
| private static final int PARKING | |
| parkPermit | back to summary |
|---|---|
| private volatile boolean parkPermit | |
| PINNED | back to summary |
|---|---|
| private static final int PINNED | |
| runContinuation | back to summary |
|---|---|
| private final Runnable runContinuation | |
| RUNNING | back to summary |
|---|---|
| private static final int RUNNING | |
| scheduler | back to summary |
|---|---|
| private final Executor scheduler | |
| STARTED | back to summary |
|---|---|
| private static final int STARTED | |
| STATE | back to summary |
|---|---|
| private static final long STATE | |
| state | back to summary |
|---|---|
| private volatile int state | |
| TERMINATED | back to summary |
|---|---|
| private static final int TERMINATED | |
| TIMED_PARKED | back to summary |
|---|---|
| private static final int TIMED_PARKED | |
| TIMED_PARKING | back to summary |
|---|---|
| private static final int TIMED_PARKING | |
| TIMED_PINNED | back to summary |
|---|---|
| private static final int TIMED_PINNED | |
| TIMED_WAIT | back to summary |
|---|---|
| private static final int TIMED_WAIT | |
| TIMED_WAITING | back to summary |
|---|---|
| private static final int TIMED_WAITING | |
| timedWaitSeqNo | back to summary |
|---|---|
| private byte timedWaitSeqNo | |
| timeout | back to summary |
|---|---|
| private long timeout | |
| timeoutTask | back to summary |
|---|---|
| private Future<?> timeoutTask | |
| U | back to summary |
|---|---|
| private static final Unsafe U | |
| UNBLOCKED | back to summary |
|---|---|
| private static final int UNBLOCKED | |
| UNPARKED | back to summary |
|---|---|
| private static final int UNPARKED | |
| VTHREAD_SCOPE | back to summary |
|---|---|
| private static final ContinuationScope VTHREAD_SCOPE | |
| WAIT | back to summary |
|---|---|
| private static final int WAIT | |
| WAITING | back to summary |
|---|---|
| private static final int WAITING | |
| YIELDED | back to summary |
|---|---|
| private static final int YIELDED | |
| YIELDING | back to summary |
|---|---|
| private static final int YIELDING | |
| VirtualThread | back to summary |
|---|---|
| pack-priv VirtualThread(Executor scheduler, String name, int characteristics, Runnable task) Creates a new | |
| afterDone | back to summary |
|---|---|
| private void afterDone() Invoked after the continuation completes. | |
| afterDone | back to summary |
|---|---|
| private void afterDone(boolean notifyContainer) Invoked after the continuation completes (or start failed). Sets the thread state to TERMINATED and notifies anyone waiting for the thread to terminate.
| |
| afterYield | back to summary |
|---|---|
| private void afterYield() Invoked in the context of the carrier thread after the Continuation yields when parking, blocking on monitor enter, Object.wait, or Thread.yield. | |
| alive | back to summary |
|---|---|
| pack-priv boolean alive() Overrides java. Doc from java. Returns true if this thread is alive. This method is non-final so it can be overridden.
| |
| appendCarrierInfo | back to summary |
|---|---|
| private boolean appendCarrierInfo(StringBuilder sb) Appends the carrier state and thread name to the string buffer if mounted.
| |
| beforeJoin | back to summary |
|---|---|
| pack-priv void beforeJoin() Invoked by Thread.join before a thread waits for this virtual thread to terminate. | |
| blockedOn | back to summary |
|---|---|
| pack-priv void blockedOn(Interruptible b) Overrides java.
| |
| cancelTimeoutTask | back to summary |
|---|---|
| private void cancelTimeoutTask() Cancel timeout task when continuing after timed-park or timed-wait. The timeout task may be executing, or may have already completed. | |
| carrierThreadAccessLock | back to summary |
|---|---|
| private Object carrierThreadAccessLock() Returns the lock object to synchronize on when accessing carrierThread. The lock prevents carrierThread from being reset to null during unmount. | |
| compareAndSetOnWaitingList | back to summary |
|---|---|
| private boolean compareAndSetOnWaitingList(boolean expectedValue, boolean newValue) | |
| compareAndSetState | back to summary |
|---|---|
| private boolean compareAndSetState(int expectedValue, int newValue) | |
| continuationScope | back to summary |
|---|---|
| pack-priv static ContinuationScope continuationScope() Returns the continuation scope used for virtual threads. | |
| createDefaultScheduler | back to summary |
|---|---|
| private static ForkJoinPool createDefaultScheduler() Creates the default ForkJoinPool scheduler. | |
| defaultScheduler | back to summary |
|---|---|
| pack-priv static Executor defaultScheduler() Returns the default scheduler. | |
| disableSuspendAndPreempt | back to summary |
|---|---|
| private void disableSuspendAndPreempt() Disallow the current thread be suspended or preempted. | |
| enableSuspendAndPreempt | back to summary |
|---|---|
| private void enableSuspendAndPreempt() Allow the current thread be suspended or preempted. | |
| endFirstTransition | back to summary |
|---|---|
private native void endFirstTransition()
| |
| endTransition | back to summary |
|---|---|
private native void endTransition(boolean mount)
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| |
| externalSubmitRunContinuation | back to summary |
|---|---|
| private void externalSubmitRunContinuation(ForkJoinPool pool) Submits the runContinuation task to the given scheduler as an external submit. If OutOfMemoryError is thrown then the submit will be retried until it succeeds. | |
| externalSubmitRunContinuationOrThrow | back to summary |
|---|---|
| private void externalSubmitRunContinuationOrThrow() Submits the runContinuation task to the scheduler. For the default scheduler, and calling it a virtual thread that uses the default scheduler, the task will be pushed to an external submission queue. This method may throw OutOfMemoryError. | |
| getAndClearInterrupt | back to summary |
|---|---|
| pack-priv boolean getAndClearInterrupt() Overrides java.
| |
| getAndSetParkPermit | back to summary |
|---|---|
| private boolean getAndSetParkPermit(boolean newValue) | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| interrupt | back to summary |
|---|---|
| public void interrupt() Overrides java. Doc from java. Interrupts this thread. If this thread is blocked in an invocation of the If this thread is blocked in an I/O operation upon an If this thread is blocked in a If none of the previous conditions hold then this thread's interrupted status will be set. Interrupting a thread that is not alive need not have any effect.
| |
| isInterrupted | back to summary |
|---|---|
| public boolean isInterrupted() Overrides java. Doc from java. Tests whether this thread has been interrupted. The interrupted status of the thread is unaffected by this method.
| |
| isTerminated | back to summary |
|---|---|
| pack-priv boolean isTerminated() Overrides java. Doc from java. Returns true if the thread has terminated.
| |
| lazySubmitRunContinuation | back to summary |
|---|---|
| private void lazySubmitRunContinuation() Lazy submit the runContinuation task if invoked on a carrier thread and its local queue is empty. If not empty, or invoked by another thread, then this method works like submitRunContinuation and just submits the task to the scheduler. If OutOfMemoryError is thrown then the submit will be retried until it succeeds. | |
| mount | back to summary |
|---|---|
| private void mount() Mounts this virtual thread onto the current platform thread. On return, the current thread is the virtual thread.
| |
| notifyJvmtiDisableSuspend | back to summary |
|---|---|
private static native void notifyJvmtiDisableSuspend(boolean enter)
| |
| park | back to summary |
|---|---|
| pack-priv void park() Implements abstract java. Parks until unparked or interrupted. If already unparked then the parking permit is consumed and this method completes immediately (meaning it doesn't yield). It also completes immediately if the interrupted status is set.
| |
| parkNanos | back to summary |
|---|---|
| pack-priv void parkNanos(long nanos) Implements abstract java. Parks up to the given waiting time or until unparked or interrupted.
If already unparked then the parking permit is consumed and this method
completes immediately (meaning it doesn't yield). It also completes immediately
if the interrupted status is set or the waiting time is
| |
| parkOnCarrierThread | back to summary |
|---|---|
| private void parkOnCarrierThread(boolean timed, long nanos) Parks the current carrier thread up to the given waiting time or until unparked or interrupted. If the virtual thread is interrupted then the interrupted status will be propagated to the carrier thread.
| |
| parkTimeoutExpired | back to summary |
|---|---|
| private void parkTimeoutExpired() Invoked by FJP worker thread or STPE thread when park timeout expires. | |
| postPinnedEvent | back to summary |
|---|---|
| private static native void postPinnedEvent(String op) Call into VM when pinned to record a JFR jdk.VirtualThreadPinned event. Recording the event in the VM avoids having JFR event recorded in Java with the same name, but different ID, to events recorded by the VM.
| |
| registerNatives | back to summary |
|---|---|
| private static native void registerNatives() | |
| run | back to summary |
|---|---|
| private void run(Runnable task) Runs a task in the context of this virtual thread. | |
| run | back to summary |
|---|---|
| public void run() Overrides java. Implements java. Doc from java. This method is run by the thread when it executes. Subclasses of This method is not intended to be invoked directly. If this thread is a
platform thread created with a
| |
| runContinuation | back to summary |
|---|---|
| private void runContinuation() Runs or continues execution on the current thread. The virtual thread is mounted on the current thread before the task runs or continues. It unmounts when the task completes or yields.
| |
| schedule | back to summary |
|---|---|
| private Future Schedule a runnable task to run after a delay. | |
| setCarrierThread | back to summary |
|---|---|
| private void setCarrierThread(Thread carrier) | |
| setParkPermit | back to summary |
|---|---|
| private void setParkPermit(boolean newValue) | |
| setState | back to summary |
|---|---|
| private void setState(int newValue) | |
| sleepNanos | back to summary |
|---|---|
| pack-priv void sleepNanos(long nanos) throws InterruptedException Hides java. Sleep the current thread for the given sleep time (in nanoseconds). If nanos is 0 then the thread will attempt to yield. Implementation Note This implementation parks the thread for the given sleeping time and will therefore be observed in PARKED state during the sleep. Parking will consume the parking permit so this method makes available the parking permit after the sleep. This may be observed as a spurious, but benign, wakeup when the thread subsequently attempts to park.
| |
| start | back to summary |
|---|---|
| pack-priv void start(ThreadContainer container) Overrides java. Schedules this
| |
| start | back to summary |
|---|---|
| public void start() Overrides java. Doc from java. Schedules this thread to begin execution. The thread will execute independently of the current thread. A thread can be started at most once. In particular, a thread can not be restarted after it has terminated.
| |
| startFinalTransition | back to summary |
|---|---|
private native void startFinalTransition()
| |
| startTransition | back to summary |
|---|---|
private native void startTransition(boolean mount)
| |
| state | back to summary |
|---|---|
| private int state() | |
| submit | back to summary |
|---|---|
| private void submit(Executor executor, Runnable task) Submits the given task to the given executor. If the scheduler is a ForkJoinPool then the task is first adapted to a ForkJoinTask. | |
| submitFailed | back to summary |
|---|---|
| private void submitFailed(RejectedExecutionException ree) If enabled, emits a JFR VirtualThreadSubmitFailedEvent. | |
| submitRunContinuation | back to summary |
|---|---|
| private void submitRunContinuation(Executor scheduler, boolean retryOnOOME) Submits the runContinuation task to the scheduler. For the default scheduler, and calling it on a worker thread, the task will be pushed to the local queue, otherwise it will be pushed to an external submission queue.
| |
| submitRunContinuation | back to summary |
|---|---|
| private void submitRunContinuation() Submits the runContinuation task to the scheduler. For the default scheduler, and calling it on a worker thread, the task will be pushed to the local queue, otherwise it will be pushed to an external submission queue. If OutOfMemoryError is thrown then the submit will be retried until it succeeds. | |
| takeVirtualThreadListToUnblock | back to summary |
|---|---|
| private static native VirtualThread takeVirtualThreadListToUnblock() Retrieves the list of virtual threads that are waiting to be unblocked, waiting if necessary until a list of one or more threads becomes available. | |
| threadState | back to summary |
|---|---|
| pack-priv Thread. Overrides java. Doc from java. Returns the state of this thread. This method can be used instead of getState as getState is not final and so can be overridden to run arbitrary code.
| |
| timedWaitLock | back to summary |
|---|---|
| private Object timedWaitLock() Returns a lock object for coordinating timed-wait setup and timeout handling. | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of this thread. The string representation will usually include the thread's identifier and name. The default implementation for platform threads includes the thread's identifier, name, priority, and the name of the thread group.
| |
| tryYield | back to summary |
|---|---|
| pack-priv void tryYield() Attempts to yield the current virtual thread (Thread.yield). | |
| unblock | back to summary |
|---|---|
| private void unblock() Invoked by unblocker thread to unblock this virtual thread. | |
| unblockVirtualThreads | back to summary |
|---|---|
| private static void unblockVirtualThreads() Schedule virtual threads that are ready to be scheduled after they blocked on monitor enter. | |
| unmount | back to summary |
|---|---|
| private void unmount() Unmounts this virtual thread from the carrier. On return, the current thread is the current platform thread.
| |
| unpark | back to summary |
|---|---|
| private void unpark(boolean lazySubmit) Re-enables this virtual thread for scheduling. If this virtual thread is parked
then its task is scheduled to continue, otherwise its next call to
| |
| unpark | back to summary |
|---|---|
| pack-priv void unpark() Implements abstract java. Doc from java. Makes available the parking permit to the given this virtual thread.
| |
| waitTimeoutExpired | back to summary |
|---|---|
| private void waitTimeoutExpired(byte seqNo) Invoked by FJP worker thread or STPE thread when wait timeout expires. If the virtual thread is in timed-wait then this method will unblock the thread and submit its task so that it continues and attempts to reenter the monitor. This method does nothing if the thread has been woken by notify or interrupt. | |
| yieldContinuation | back to summary |
|---|---|
| private boolean yieldContinuation() Invokes Continuation.yield, notifying JVMTI (if enabled) to hide frames until the continuation continues.
| |
| Modifier and Type | Field and Description |
|---|---|
| private static final ScheduledExecutorService[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static ScheduledExecutorService[] | |
| pack-priv static Future |
| INSTANCE | back to summary |
|---|---|
| private static final ScheduledExecutorService[] INSTANCE | |
| DelayedTaskSchedulers | back to summary |
|---|---|
| private DelayedTaskSchedulers() | |
| createDelayedTaskSchedulers | back to summary |
|---|---|
| private static ScheduledExecutorService[] createDelayedTaskSchedulers() | |
| schedule | back to summary |
|---|---|
| pack-priv static Future | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected void | onPinned(Continuation.
Overrides jdk. Called when suspending if the continuation is pinned |
| private static Runnable |
| VThreadContinuation | back to summary |
|---|---|
| pack-priv VThreadContinuation(VirtualThread vthread, Runnable task) | |
| onPinned | back to summary |
|---|---|
| protected void onPinned(Continuation. Overrides jdk. Doc from jdk. Called when suspending if the continuation is pinned
| |
| wrap | back to summary |
|---|---|
| private static Runnable wrap(VirtualThread vthread, Runnable task) | |