- All Superinterfaces:
Thread.BuilderPREVIEW
- Enclosing interface:
Thread.BuilderPREVIEW
OfVirtual is a preview API of the Java platform.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
A builder for creating a virtual
Thread or ThreadFactory
that creates virtual threads.
Unless otherwise specified, passing a null argument to a method in
this interface causes a NullPointerException to be thrown.
- Since:
- 19
- See Also:
-
Nested Class Summary
Nested classes/interfaces declared in interface java.lang.Thread.BuilderPREVIEW
Thread.Builder.OfPlatformPREVIEW, Thread.Builder.OfVirtualPREVIEW -
Method Summary
Modifier and TypeMethodDescriptionallowSetThreadLocals(boolean allow) Sets whether the thread is allowed to set values for its copy of thread-local variables.inheritInheritableThreadLocals(boolean inherit) Sets whether the thread inherits the initial values of inheritable-thread-local variables from the constructing thread.Sets the thread name.Sets the thread name to be the concatenation of a string prefix and the string representation of a counter value.Sets the uncaught exception handler.Methods declared in interface java.lang.Thread.BuilderPREVIEW
factory, start, unstarted
-
Method Details
-
name
Description copied from interface:Thread.BuilderSets the thread name.- Specified by:
namein interfaceThread.BuilderPREVIEW- Parameters:
name- thread name- Returns:
- this builder
-
name
Description copied from interface:Thread.BuilderSets the thread name to be the concatenation of a string prefix and the string representation of a counter value. The counter's initial value isstart. It is incremented after aThreadis created with this builder so that the next thread is named with the new counter value. AThreadFactorycreated with this builder is seeded with the current value of the counter. TheThreadFactoryincrements its copy of the counter afternewThreadis used to create aThread.- Specified by:
namein interfaceThread.BuilderPREVIEW- Parameters:
prefix- thread name prefixstart- the starting value of the counter- Returns:
- this builder
- Throws:
IllegalArgumentException- if start is negative
-
allowSetThreadLocals
Description copied from interface:Thread.BuilderSets whether the thread is allowed to set values for its copy of thread-local variables. The default is to allow. If not allowed, then any attempt by the thread to set a value for a thread-local with theThreadLocal.set(Object)method throwsUnsupportedOperationException. Any attempt to set the thread's context class loader withsetContextClassLoaderalso throws. TheThreadLocal.get()method always returns the initial-value when thread locals are not allowed.- Specified by:
allowSetThreadLocalsin interfaceThread.BuilderPREVIEW- Parameters:
allow-trueto allow,falseto disallow- Returns:
- this builder
-
inheritInheritableThreadLocals
Description copied from interface:Thread.BuilderSets whether the thread inherits the initial values of inheritable-thread-local variables from the constructing thread. The default is to inherit.The initial values of
InheritableThreadLocals are never inherited whenThread.Builder.allowSetThreadLocals(boolean)PREVIEW is used to disallow the thread to have its own copy of thread-local variables.- Specified by:
inheritInheritableThreadLocalsin interfaceThread.BuilderPREVIEW- Parameters:
inherit-trueto inherit,falseto not inherit- Returns:
- this builder
-
uncaughtExceptionHandler
Description copied from interface:Thread.BuilderSets the uncaught exception handler.- Specified by:
uncaughtExceptionHandlerin interfaceThread.BuilderPREVIEW- Parameters:
ueh- uncaught exception handler- Returns:
- this builder
-
OfVirtualwhen preview features are enabled.