Skip to content

Commit

Permalink
Mkae easier to set daemon status
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanBateman committed Feb 27, 2021
1 parent 4563be0 commit 1092205
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/java.base/share/classes/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,13 @@ public interface VirtualThreadTask extends Runnable {
* // Starts a daemon thread with name "duke"
* Thread thread = Thread.builder()
* .name("duke")
* .daemon(true)
* .daemon()
* .priority(Thread.NORM_PRIORITY)
* .task(runnable)
* .start();
*
* // A ThreadFactory that creates daemon threads named "worker-0", "worker-1", ...
* ThreadFactory factory = Thread.builder().daemon(true).name("worker-", 0).factory();
* ThreadFactory factory = Thread.builder().daemon().name("worker-", 0).factory();
*
* // Start an unnamed virtual thread
* Thread thread = Thread.builder().virtual().task(runnable).start();
Expand Down Expand Up @@ -876,6 +876,18 @@ default Thread start() {
*/
Builder daemon(boolean on);

/**
* Sets the daemon status to {@code true}.
* The {@link #isDaemon() daemon status} of virtual threads is always {@code true}.
* Setting the daemon status of a virtual thread has no effect.??
* @implSpec The default implementation invokes {@linkplain #daemon(boolean)} with
* a value of {@code true}.
* @return this builder
*/
default Builder daemon() {
return daemon(true);
}

/**
* Sets the thread priority.
* The priority of virtual threads is always {@linkplain Thread#NORM_PRIORITY}.
Expand Down

0 comments on commit 1092205

Please sign in to comment.