Module java.base
Package java.lang

# Interface Thread.Builder.OfVirtual

All Superinterfaces:
  `Thread.BuilderPREVIEW`

Enclosing interface:
  `Thread.BuilderPREVIEW`

public static sealed interface Thread.Builder.OfVirtual extends Thread.BuilderPREVIEW
`OfVirtual` is a preview API of the Java platform.
Programs can only use `OfVirtual` when preview features are enabled.
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:
  - `Thread.ofVirtual()`PREVIEW

- ## Nested Class Summary

  ## Nested classes/interfaces declared in interface java.lang.Thread.BuilderPREVIEW

  `Thread.Builder.OfPlatformPREVIEW, Thread.Builder.OfVirtualPREVIEW`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Thread.Builder.OfVirtualPREVIEW`
  `allowSetThreadLocals(boolean allow)`
  Sets whether the thread is allowed to set values for its copy of thread-local variables.
  `Thread.Builder.OfVirtualPREVIEW`
  `inheritInheritableThreadLocals(boolean inherit)`
  Sets whether the thread inherits the initial values of inheritable-thread-local variables from the constructing thread.
  `Thread.Builder.OfVirtualPREVIEW`
  `name(String name)`
  Sets the thread name.
  `Thread.Builder.OfVirtualPREVIEW`
  `name(String prefix, long start)`
  Sets the thread name to be the concatenation of a string prefix and the string representation of a counter value.
  `Thread.Builder.OfVirtualPREVIEW`
  `uncaughtExceptionHandler(Thread.UncaughtExceptionHandler ueh)`
  Sets the uncaught exception handler.

  ### Methods declared in interface java.lang.Thread.BuilderPREVIEW

  `factory, start, unstarted`

- ## Method Details

  - ### name

    Thread.Builder.OfVirtualPREVIEW name(String name)
    Description copied from interface: `Thread.Builder`
    Sets the thread name.
    Specified by:
      `name` in interface `Thread.BuilderPREVIEW`
    Parameters:
      `name` - thread name
    Returns:
      this builder

  - ### name

    Thread.Builder.OfVirtualPREVIEW name(String prefix, long start)
    Description copied from interface: `Thread.Builder`
    Sets the thread name to be the concatenation of a string prefix and the string representation of a counter value. The counter's initial value is `start`. It is incremented after a `Thread` is created with this builder so that the next thread is named with the new counter value. A `ThreadFactory` created with this builder is seeded with the current value of the counter. The `ThreadFactory` increments its copy of the counter after `newThread` is used to create a `Thread`.
    Specified by:
      `name` in interface `Thread.BuilderPREVIEW`
    Parameters:
      `prefix` - thread name prefix
      `start` - the starting value of the counter
    Returns:
      this builder
    Throws:
      `IllegalArgumentException` - if start is negative

  - ### allowSetThreadLocals

    Thread.Builder.OfVirtualPREVIEW allowSetThreadLocals(boolean allow)
    Description copied from interface: `Thread.Builder`
    Sets 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 the `ThreadLocal.set(Object)` method throws `UnsupportedOperationException`. Any attempt to set the thread's context class loader with `setContextClassLoader` also throws. The `ThreadLocal.get()` method always returns the initial-value when thread locals are not allowed.
    Specified by:
      `allowSetThreadLocals` in interface `Thread.BuilderPREVIEW`
    Parameters:
      `allow` - `true` to allow, `false` to disallow
    Returns:
      this builder

  - ### inheritInheritableThreadLocals

    Thread.Builder.OfVirtualPREVIEW inheritInheritableThreadLocals(boolean inherit)
    Description copied from interface: `Thread.Builder`
    Sets 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 `InheritableThreadLocal`s are never inherited when `Thread.Builder.allowSetThreadLocals(boolean)`PREVIEW is used to disallow the thread to have its own copy of thread-local variables.

    Specified by:
      `inheritInheritableThreadLocals` in interface `Thread.BuilderPREVIEW`
    Parameters:
      `inherit` - `true` to inherit, `false` to not inherit
    Returns:
      this builder

  - ### uncaughtExceptionHandler

    Thread.Builder.OfVirtualPREVIEW uncaughtExceptionHandler(Thread.UncaughtExceptionHandler ueh)
    Description copied from interface: `Thread.Builder`
    Sets the uncaught exception handler.
    Specified by:
      `uncaughtExceptionHandler` in interface `Thread.BuilderPREVIEW`
    Parameters:
      `ueh` - uncaught exception handler
    Returns:
      this builder