APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.lang

pack-priv final Class VirtualThread

extends BaseVirtualThread
Class Inheritance
Imports
java.util.Locale, .Objects, java.util.concurrent.Executor, .Executors, .ForkJoinPool, .ForkJoinPool.ForkJoinWorkerThreadFactory, .ForkJoinTask, .Future, .RejectedExecutionException, .ScheduledExecutorService, .ScheduledThreadPoolExecutor, .TimeUnit, jdk.internal.event.VirtualThreadEndEvent, .VirtualThreadStartEvent, .VirtualThreadSubmitFailedEvent, jdk.internal.misc.CarrierThread, .InnocuousThread, .Unsafe, jdk.internal.vm.Continuation, .ContinuationScope, .StackableScope, .ThreadContainer, .ThreadContainers, jdk.internal.vm.annotation.ChangesCurrentThread, .Hidden, .IntrinsicCandidate, .JvmtiHideEvents, .JvmtiMountTransition, .ReservedStackAccess, sun.nio.ch.Interruptible

A thread that is scheduled by the Java virtual machine rather than the operating system.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
VirtualThread.DelayedTaskSchedulers

Supports scheduling a runnable task to run after a delay.

private static class
VirtualThread.VThreadContinuation

The continuation that a virtual thread executes.

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private volatile boolean
private static final long
private volatile Thread
private final Continuation
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
U

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

Constructor Summary

AccessConstructor 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 VirtualThread to run the given task with the given scheduler.

Method Summary

Modifier and TypeMethod and Description
private void
afterDone()

Invoked after the continuation completes.

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
alive()

Overrides java.lang.Thread.alive.

Returns true if this thread is alive.

private boolean

Returns:

true if mounted, false if not mounted
appendCarrierInfo
(StringBuilder sb)

Appends the carrier state and thread name to the string buffer if mounted.

pack-priv void
beforeJoin()

Invoked by Thread.join before a thread waits for this virtual thread to terminate.

pack-priv void
private void
cancelTimeoutTask()

Cancel timeout task when continuing after timed-park or timed-wait.

private Object
carrierThreadAccessLock()

Returns the lock object to synchronize on when accessing carrierThread.

private boolean
compareAndSetOnWaitingList(boolean expectedValue, boolean newValue)

private boolean
compareAndSetState(int expectedValue, int newValue)

pack-priv static ContinuationScope
continuationScope()

Returns the continuation scope used for virtual threads.

private static ForkJoinPool
createDefaultScheduler()

Creates the default ForkJoinPool scheduler.

pack-priv static Executor
defaultScheduler()

Returns the default scheduler.

private void
disableSuspendAndPreempt()

Disallow the current thread be suspended or preempted.

private void
enableSuspendAndPreempt()

Allow the current thread be suspended or preempted.

private native void
private native void
endTransition(boolean mount)

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

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
externalSubmitRunContinuationOrThrow()

Submits the runContinuation task to the scheduler.

pack-priv boolean
private boolean
getAndSetParkPermit(boolean newValue)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public void
interrupt()

Overrides java.lang.Thread.interrupt.

Interrupts this thread.

public boolean
isInterrupted()

Overrides java.lang.Thread.isInterrupted.

Tests whether this thread has been interrupted.

pack-priv boolean
isTerminated()

Overrides java.lang.Thread.isTerminated.

Returns true if the thread has terminated.

private void
lazySubmitRunContinuation()

Lazy submit the runContinuation task if invoked on a carrier thread and its local queue is empty.

private void
mount()

Mounts this virtual thread onto the current platform thread.

private static native void
pack-priv void
park()

Implements abstract java.lang.BaseVirtualThread.park.

Parks until unparked or interrupted.

pack-priv void
parkNanos(long
the maximum number of nanoseconds to wait.
nanos
)

Implements abstract java.lang.BaseVirtualThread.parkNanos.

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
parkTimeoutExpired()

Invoked by FJP worker thread or STPE thread when park timeout expires.

private static native void
postPinnedEvent(String op)

Call into VM when pinned to record a JFR jdk.VirtualThreadPinned event.

private static native void
private void
run(Runnable task)

Runs a task in the context of this virtual thread.

public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

This method is run by the thread when it executes.

private void
runContinuation()

Runs or continues execution on the current thread.

private Future<?>
schedule(Runnable command, long delay, TimeUnit unit)

Schedule a runnable task to run after a delay.

private void
private void
setParkPermit(boolean newValue)

private void
setState(int newValue)

pack-priv void
sleepNanos(long
the maximum number of nanoseconds to sleep
nanos
)

Hides java.lang.Thread.sleepNanos.

Sleep the current thread for the given sleep time (in nanoseconds).

pack-priv void
start(ThreadContainer container)

Overrides java.lang.Thread.start.

Schedules this VirtualThread to execute.

public void
start()

Overrides java.lang.Thread.start.

Schedules this thread to begin execution.

private native void
private native void
startTransition(boolean mount)

private int
private void
submit(Executor executor, Runnable task)

Submits the given task to the given executor.

private void
submitFailed(RejectedExecutionException ree)

If enabled, emits a JFR VirtualThreadSubmitFailedEvent.

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
submitRunContinuation()

Submits the runContinuation task to the scheduler.

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.State
threadState()

Overrides java.lang.Thread.threadState.

Returns the state of this thread.

private Object
timedWaitLock()

Returns a lock object for coordinating timed-wait setup and timeout handling.

public String
toString()

Overrides java.lang.Thread.toString.

Returns a string representation of this thread.

pack-priv void
tryYield()

Attempts to yield the current virtual thread (Thread.yield).

private void
unblock()

Invoked by unblocker thread to unblock this virtual thread.

private static void
unblockVirtualThreads()

Schedule virtual threads that are ready to be scheduled after they blocked on monitor enter.

private void
unmount()

Unmounts this virtual thread from the carrier.

private void
unpark(boolean
to use lazySubmit if possible
lazySubmit
)

Re-enables this virtual thread for scheduling.

pack-priv void
unpark()

Implements abstract java.lang.BaseVirtualThread.unpark.

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.

Field Detail

BLOCKEDback to summary
private static final int BLOCKED
BLOCKINGback to summary
private static final int BLOCKING
blockPermitback to summary
private volatile boolean blockPermit
CARRIER_THREADback to summary
private static final long CARRIER_THREAD
carrierThreadback to summary
private volatile Thread carrierThread
contback to summary
private final Continuation cont

Hides java.lang.Thread.cont.

DEFAULT_SCHEDULERback to summary
private static final ForkJoinPool DEFAULT_SCHEDULER
interruptibleWaitback to summary
private volatile boolean interruptibleWait
NEWback to summary
private static final int NEW
nextback to summary
private volatile VirtualThread next
notifiedback to summary
private volatile boolean notified
notifyAllAfterTerminateback to summary
private volatile boolean notifyAllAfterTerminate
ON_WAITING_LISTback to summary
private static final long ON_WAITING_LIST
onWaitingListback to summary
private volatile boolean onWaitingList
PARK_PERMITback to summary
private static final long PARK_PERMIT
PARKEDback to summary
private static final int PARKED
PARKINGback to summary
private static final int PARKING
parkPermitback to summary
private volatile boolean parkPermit
PINNEDback to summary
private static final int PINNED
runContinuationback to summary
private final Runnable runContinuation
RUNNINGback to summary
private static final int RUNNING
schedulerback to summary
private final Executor scheduler
STARTEDback to summary
private static final int STARTED
STATEback to summary
private static final long STATE
stateback to summary
private volatile int state
TERMINATEDback to summary
private static final int TERMINATED
TIMED_PARKEDback to summary
private static final int TIMED_PARKED
TIMED_PARKINGback to summary
private static final int TIMED_PARKING
TIMED_PINNEDback to summary
private static final int TIMED_PINNED
TIMED_WAITback to summary
private static final int TIMED_WAIT
TIMED_WAITINGback to summary
private static final int TIMED_WAITING
timedWaitSeqNoback to summary
private byte timedWaitSeqNo
timeoutback to summary
private long timeout
timeoutTaskback to summary
private Future<?> timeoutTask
Uback to summary
private static final Unsafe U
UNBLOCKEDback to summary
private static final int UNBLOCKED
UNPARKEDback to summary
private static final int UNPARKED
VTHREAD_SCOPEback to summary
private static final ContinuationScope VTHREAD_SCOPE
WAITback to summary
private static final int WAIT
WAITINGback to summary
private static final int WAITING
YIELDEDback to summary
private static final int YIELDED
YIELDINGback to summary
private static final int YIELDING

Constructor Detail

VirtualThreadback to summary
pack-priv VirtualThread(Executor scheduler, String name, int characteristics, Runnable task)

Creates a new VirtualThread to run the given task with the given scheduler. If the given scheduler is null and the current thread is a platform thread then the newly created virtual thread will use the default scheduler. If given scheduler is null and the current thread is a virtual thread then the current thread's scheduler is used.

Parameters
scheduler:Executor

the scheduler or null

name:String

thread name

characteristics:int

characteristics

task:Runnable

the task to execute

Method Detail

afterDoneback to summary
private void afterDone()

Invoked after the continuation completes.

afterDoneback 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.

Parameters
notifyContainer:boolean

true if its container should be notified

afterYieldback 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.

aliveback to summary
pack-priv boolean alive()

Overrides java.lang.Thread.alive.

Doc from java.lang.Thread.alive.

Returns true if this thread is alive. This method is non-final so it can be overridden.

Annotations
@Override
appendCarrierInfoback to summary
private boolean appendCarrierInfo(StringBuilder sb)

Appends the carrier state and thread name to the string buffer if mounted.

Returns:boolean

true if mounted, false if not mounted

beforeJoinback to summary
pack-priv void beforeJoin()

Invoked by Thread.join before a thread waits for this virtual thread to terminate.

blockedOnback to summary
pack-priv void blockedOn(Interruptible b)

Overrides java.lang.Thread.blockedOn.

Annotations
@Override
cancelTimeoutTaskback 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.

carrierThreadAccessLockback 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.

compareAndSetOnWaitingListback to summary
private boolean compareAndSetOnWaitingList(boolean expectedValue, boolean newValue)
compareAndSetStateback to summary
private boolean compareAndSetState(int expectedValue, int newValue)
continuationScopeback to summary
pack-priv static ContinuationScope continuationScope()

Returns the continuation scope used for virtual threads.

createDefaultSchedulerback to summary
private static ForkJoinPool createDefaultScheduler()

Creates the default ForkJoinPool scheduler.

defaultSchedulerback to summary
pack-priv static Executor defaultScheduler()

Returns the default scheduler.

disableSuspendAndPreemptback to summary
private void disableSuspendAndPreempt()

Disallow the current thread be suspended or preempted.

enableSuspendAndPreemptback to summary
private void enableSuspendAndPreempt()

Allow the current thread be suspended or preempted.

endFirstTransitionback to summary
private native void endFirstTransition()
Annotations
@IntrinsicCandidate
@JvmtiMountTransition
endTransitionback to summary
private native void endTransition(boolean mount)
Annotations
@IntrinsicCandidate
@JvmtiMountTransition
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

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.

Annotations
@Override
externalSubmitRunContinuationback 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.

See Also
ForkJoinPool#externalSubmit(ForkJoinTask)
externalSubmitRunContinuationOrThrowback 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.

getAndClearInterruptback to summary
pack-priv boolean getAndClearInterrupt()

Overrides java.lang.Thread.getAndClearInterrupt.

Annotations
@Override
getAndSetParkPermitback to summary
private boolean getAndSetParkPermit(boolean newValue)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
interruptback to summary
public void interrupt()

Overrides java.lang.Thread.interrupt.

Doc from java.lang.Thread.interrupt.

Interrupts this thread.

If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int) methods of this class, then its interrupted status will be cleared and it will receive an InterruptedException.

If this thread is blocked in an I/O operation upon an InterruptibleChannel then the channel will be closed, the thread's interrupted status will be set, and the thread will receive a java.nio.channels.ClosedByInterruptException.

If this thread is blocked in a java.nio.channels.Selector then the thread's interrupted status will be set and it will return immediately from the selection operation, possibly with a non-zero value, just as if the selector's wakeup method were invoked.

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.

Annotations
@Override
isInterruptedback to summary
public boolean isInterrupted()

Overrides java.lang.Thread.isInterrupted.

Doc from java.lang.Thread.isInterrupted.

Tests whether this thread has been interrupted. The interrupted status of the thread is unaffected by this method.

Annotations
@Override
isTerminatedback to summary
pack-priv boolean isTerminated()

Overrides java.lang.Thread.isTerminated.

Doc from java.lang.Thread.isTerminated.

Returns true if the thread has terminated.

Annotations
@Override
lazySubmitRunContinuationback 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.

See Also
ForkJoinPool#lazySubmit(ForkJoinTask)
mountback to summary
private void mount()

Mounts this virtual thread onto the current platform thread. On return, the current thread is the virtual thread.

Annotations
@ChangesCurrentThread
@ReservedStackAccess
notifyJvmtiDisableSuspendback to summary
private static native void notifyJvmtiDisableSuspend(boolean enter)
Annotations
@IntrinsicCandidate
parkback to summary
pack-priv void park()

Implements abstract java.lang.BaseVirtualThread.park.

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.

Annotations
@Override
parkNanosback to summary
pack-priv void parkNanos(long nanos)

Implements abstract java.lang.BaseVirtualThread.parkNanos.

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 <= 0.

Parameters
nanos:long

the maximum number of nanoseconds to wait.

Annotations
@Override
parkOnCarrierThreadback 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.

Parameters
timed:boolean

true for a timed park, false for untimed

nanos:long

the waiting time in nanoseconds

parkTimeoutExpiredback to summary
private void parkTimeoutExpired()

Invoked by FJP worker thread or STPE thread when park timeout expires.

postPinnedEventback 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.

Annotations
@Hidden
registerNativesback to summary
private static native void registerNatives()

Hides java.lang.Thread.registerNatives.

runback to summary
private void run(Runnable task)

Runs a task in the context of this virtual thread.

runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.

Annotations
@Override
runContinuationback 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.

Annotations
@ChangesCurrentThread
scheduleback to summary
private Future<?> schedule(Runnable command, long delay, TimeUnit unit)

Schedule a runnable task to run after a delay.

setCarrierThreadback to summary
private void setCarrierThread(Thread carrier)
setParkPermitback to summary
private void setParkPermit(boolean newValue)
setStateback to summary
private void setState(int newValue)
sleepNanosback to summary
pack-priv void sleepNanos(long nanos) throws InterruptedException

Hides java.lang.Thread.sleepNanos.

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.

Parameters
nanos:long

the maximum number of nanoseconds to sleep

Exceptions
InterruptedException:
if interrupted while sleeping
startback to summary
pack-priv void start(ThreadContainer container)

Overrides java.lang.Thread.start.

Schedules this VirtualThread to execute.

Annotations
@Override
Exceptions
IllegalStateException:
if the container is shutdown or closed
IllegalThreadStateException:
if the thread has already been started
RejectedExecutionException:
if the scheduler cannot accept a task
startback to summary
public void start()

Overrides java.lang.Thread.start.

Doc from java.lang.Thread.start.

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.

Annotations
@Override
startFinalTransitionback to summary
private native void startFinalTransition()
Annotations
@IntrinsicCandidate
@JvmtiMountTransition
startTransitionback to summary
private native void startTransition(boolean mount)
Annotations
@IntrinsicCandidate
@JvmtiMountTransition
stateback to summary
private int state()
submitback 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.

submitFailedback to summary
private void submitFailed(RejectedExecutionException ree)

If enabled, emits a JFR VirtualThreadSubmitFailedEvent.

submitRunContinuationback 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.

Parameters
scheduler:Executor

the scheduler

retryOnOOME:boolean

true to retry indefinitely if OutOfMemoryError is thrown

submitRunContinuationback 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.

takeVirtualThreadListToUnblockback 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.

threadStateback to summary
pack-priv Thread.State threadState()

Overrides java.lang.Thread.threadState.

Doc from java.lang.Thread.threadState.

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.

Annotations
@Override
timedWaitLockback to summary
private Object timedWaitLock()

Returns a lock object for coordinating timed-wait setup and timeout handling.

toStringback to summary
public String toString()

Overrides java.lang.Thread.toString.

Doc from java.lang.Thread.toString.

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.

Annotations
@Override
tryYieldback to summary
pack-priv void tryYield()

Attempts to yield the current virtual thread (Thread.yield).

unblockback to summary
private void unblock()

Invoked by unblocker thread to unblock this virtual thread.

unblockVirtualThreadsback to summary
private static void unblockVirtualThreads()

Schedule virtual threads that are ready to be scheduled after they blocked on monitor enter.

unmountback to summary
private void unmount()

Unmounts this virtual thread from the carrier. On return, the current thread is the current platform thread.

Annotations
@ChangesCurrentThread
@ReservedStackAccess
unparkback 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 park or parkNanos is guaranteed not to block.

Parameters
lazySubmit:boolean

to use lazySubmit if possible

Exceptions
RejectedExecutionException:
if the scheduler cannot accept a task
unparkback to summary
pack-priv void unpark()

Implements abstract java.lang.BaseVirtualThread.unpark.

Doc from java.lang.BaseVirtualThread.unpark.

Makes available the parking permit to the given this virtual thread.

Annotations
@Override
waitTimeoutExpiredback 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.

yieldContinuationback to summary
private boolean yieldContinuation()

Invokes Continuation.yield, notifying JVMTI (if enabled) to hide frames until the continuation continues.

Annotations
@Hidden
java.lang back to summary

private Class VirtualThread.DelayedTaskSchedulers

extends Object
Class Inheritance

Supports scheduling a runnable task to run after a delay. It uses a number of ScheduledThreadPoolExecutor instances to reduce contention on the delayed work queue used. This class is used when using a custom scheduler.

Field Summary

Modifier and TypeField and Description
private static final ScheduledExecutorService[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static ScheduledExecutorService[]
pack-priv static Future<?>
schedule(Runnable command, long delay, TimeUnit unit)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
private static final ScheduledExecutorService[] INSTANCE

Constructor Detail

DelayedTaskSchedulersback to summary
private DelayedTaskSchedulers()

Method Detail

createDelayedTaskSchedulersback to summary
private static ScheduledExecutorService[] createDelayedTaskSchedulers()
scheduleback to summary
pack-priv static Future<?> schedule(Runnable command, long delay, TimeUnit unit)
java.lang back to summary

private Class VirtualThread.VThreadContinuation

extends Continuation
Class Inheritance

The continuation that a virtual thread executes.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
onPinned(Continuation.Pinned reason)

Overrides jdk.internal.vm.Continuation.onPinned.

Called when suspending if the continuation is pinned

private static Runnable
wrap(VirtualThread vthread, Runnable task)

Inherited from jdk.internal.vm.Continuation:
getCurrentContinuationgetParentgetScopegetStackTraceisDoneisPinnedisPreemptedonContinuepinrunstackWalkerstackWalkerstackWalkertoStringtryPreemptunpinwrapWalkyield

Constructor Detail

VThreadContinuationback to summary
pack-priv VThreadContinuation(VirtualThread vthread, Runnable task)

Method Detail

onPinnedback to summary
protected void onPinned(Continuation.Pinned reason)

Overrides jdk.internal.vm.Continuation.onPinned.

Doc from jdk.internal.vm.Continuation.onPinned.

Called when suspending if the continuation is pinned

Annotations
@Override
wrapback to summary
private static Runnable wrap(VirtualThread vthread, Runnable task)