Top Description Fields Constructors Methods
jdk.internal.misc

public final Class VirtualThreads

extends Object
Class Inheritance
Imports
java.util.concurrent.TimeUnit, .RejectedExecutionException, jdk.internal.access.JavaLangAccess, .SharedSecrets

Defines static methods to support execution in the context of a virtual thread.

Field Summary

Modifier and TypeField and Description
private static final JavaLangAccess

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
park()

Parks the current virtual thread until it is unparked or interrupted.

public static void
park(long
the maximum number of nanoseconds to wait
nanos
)

Parks the current virtual thread up to the given waiting time or until it is unparked or interrupted.

public static void
parkUntil(long
absolute time, in milliseconds, from the epoch
deadline
)

Parks the current virtual thread until the given deadline or until is is unparked or interrupted.

public static void
unpark(Thread
the virtual thread to unpark
thread
)

Re-enables a virtual thread for scheduling.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

JLAback to summary
private static final JavaLangAccess JLA

Constructor Detail

VirtualThreadsback to summary
private VirtualThreads()

Method Detail

parkback to summary
public static void park()

Parks the current virtual thread until it is 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 interrupt status is set.

Exceptions
WrongThreadException:
if the current thread is not a virtual thread
parkback to summary
public static void park(long nanos)

Parks the current virtual thread up to the given waiting time or until it is 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 interrupt status is set or the waiting time is <= 0.

Parameters
nanos:long

the maximum number of nanoseconds to wait

Exceptions
WrongThreadException:
if the current thread is not a virtual thread
parkUntilback to summary
public static void parkUntil(long deadline)

Parks the current virtual thread until the given deadline or until is is 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 interrupt status is set or the deadline has past.

Parameters
deadline:long

absolute time, in milliseconds, from the epoch

Exceptions
WrongThreadException:
if the current thread is not a virtual thread
unparkback to summary
public static void unpark(Thread thread)

Re-enables a virtual thread for scheduling. If the thread was parked then it will be unblocked, otherwise its next attempt to park will not block

Parameters
thread:Thread

the virtual thread to unpark

Exceptions
IllegalArgumentException:
if the thread is not a virtual thread
RejectedExecutionException:
if the scheduler cannot accept a task