Module java.base
Package java.lang

Interface Thread.Builder.OfVirtual

All Superinterfaces:
Thread.Builder
Enclosing interface:
Thread.Builder

public static interface Thread.Builder.OfVirtual extends Thread.Builder
A builder for creating a virtual Thread or ThreadFactory that creates virtual threads.

Virtual threads created with a builder, or with a ThreadFactory created from a builder, have no permissions.

Since:
99
See Also:
Thread.ofVirtual()
  • Method Details

    • name

      Description copied from interface: Thread.Builder
      Sets the thread name.
      Specified by:
      name in interface Thread.Builder
      Parameters:
      name - thread name
      Returns:
      this builder
    • name

      Thread.Builder.OfVirtual 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.Builder
      Parameters:
      prefix - thread name prefix
      start - the starting value of the counter
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if count is negative
    • allowSetThreadLocals

      Thread.Builder.OfVirtual 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 set method throws UnsupportedOperationException and the get method always returns the initial-value.
      Specified by:
      allowSetThreadLocals in interface Thread.Builder
      Parameters:
      allow - true to allow, false to disallow
      Returns:
      this builder
    • inheritInheritableThreadLocals

      Thread.Builder.OfVirtual inheritInheritableThreadLocals(boolean inherit)
      Description copied from interface: Thread.Builder
      Sets whether the thread inherits the initial values of inheritable-thread-local variables. The default is to inherit.

      The initial values of InheritableThreadLocals are never inherited when Thread.Builder.allowSetThreadLocals(boolean) is used to disallow the thread to have its own copy of thread-local variables.

      Specified by:
      inheritInheritableThreadLocals in interface Thread.Builder
      Parameters:
      inherit - true to inherit, false to not inherit
      Returns:
      this builder
    • uncaughtExceptionHandler

      Description copied from interface: Thread.Builder
      Sets the uncaught exception handler.
      Specified by:
      uncaughtExceptionHandler in interface Thread.Builder
      Parameters:
      ueh - uncaught exception handler
      Returns:
      this builder
    • scheduler

      Thread.Builder.OfVirtual scheduler(Executor scheduler)
      Sets the scheduler. The thread will be scheduled by the Java virtual machine with the given scheduler. The scheduler's execute method is invoked with tasks of type Thread.VirtualThreadTask. It may be invoked in the context of a virtual thread. The scheduler should arrange to execute these tasks on a platform thread. Attempting to execute the task on a virtual thread causes an exception to be thrown (see Thread.VirtualThreadTask.run()). The execute method may be invoked at sensitive times (e.g. when unparking a thread) so care should be taken to not directly execute the task on the current thread.
      Parameters:
      scheduler - the scheduler or null for the default scheduler
      Returns:
      this builder