mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8304919: Implementation of Virtual Threads
Reviewed-by: lmesnik, cjplummer, psandoz, mchung, sspitsyn, jpai
This commit is contained in:
parent
39398075b7
commit
2586f36120
205 changed files with 1379 additions and 1342 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -24,7 +24,6 @@
|
|||
*/
|
||||
package java.lang;
|
||||
|
||||
import java.lang.Thread.Builder;
|
||||
import java.lang.Thread.Builder.OfPlatform;
|
||||
import java.lang.Thread.Builder.OfVirtual;
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
|
@ -41,12 +40,12 @@ import jdk.internal.vm.ContinuationSupport;
|
|||
* Defines static methods to create platform and virtual thread builders.
|
||||
*/
|
||||
class ThreadBuilders {
|
||||
private ThreadBuilders() { }
|
||||
|
||||
/**
|
||||
* Base implementation of ThreadBuilder.
|
||||
* Base class for Thread.Builder implementations.
|
||||
*/
|
||||
static abstract non-sealed
|
||||
class BaseThreadBuilder<T extends Builder> implements Builder {
|
||||
private static class BaseThreadBuilder {
|
||||
private String name;
|
||||
private long counter;
|
||||
private int characteristics;
|
||||
|
@ -76,52 +75,29 @@ class ThreadBuilders {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T name(String name) {
|
||||
void setName(String name) {
|
||||
this.name = Objects.requireNonNull(name);
|
||||
this.counter = -1;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T name(String prefix, long start) {
|
||||
void setName(String prefix, long start) {
|
||||
Objects.requireNonNull(prefix);
|
||||
if (start < 0)
|
||||
throw new IllegalArgumentException("'start' is negative");
|
||||
this.name = prefix;
|
||||
this.counter = start;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T allowSetThreadLocals(boolean allow) {
|
||||
if (allow) {
|
||||
characteristics &= ~Thread.NO_THREAD_LOCALS;
|
||||
} else {
|
||||
characteristics |= Thread.NO_THREAD_LOCALS;
|
||||
}
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T inheritInheritableThreadLocals(boolean inherit) {
|
||||
void setInheritInheritableThreadLocals(boolean inherit) {
|
||||
if (inherit) {
|
||||
characteristics &= ~Thread.NO_INHERIT_THREAD_LOCALS;
|
||||
} else {
|
||||
characteristics |= Thread.NO_INHERIT_THREAD_LOCALS;
|
||||
}
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T uncaughtExceptionHandler(UncaughtExceptionHandler ueh) {
|
||||
void setUncaughtExceptionHandler(UncaughtExceptionHandler ueh) {
|
||||
this.uhe = Objects.requireNonNull(ueh);
|
||||
return (T) this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +105,7 @@ class ThreadBuilders {
|
|||
* ThreadBuilder.OfPlatform implementation.
|
||||
*/
|
||||
static final class PlatformThreadBuilder
|
||||
extends BaseThreadBuilder<OfPlatform> implements OfPlatform {
|
||||
extends BaseThreadBuilder implements OfPlatform {
|
||||
private ThreadGroup group;
|
||||
private boolean daemon;
|
||||
private boolean daemonChanged;
|
||||
|
@ -145,6 +121,30 @@ class ThreadBuilders {
|
|||
return (name != null) ? name : Thread.genThreadName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfPlatform name(String name) {
|
||||
setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfPlatform name(String prefix, long start) {
|
||||
setName(prefix, start);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfPlatform inheritInheritableThreadLocals(boolean inherit) {
|
||||
setInheritInheritableThreadLocals(inherit);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfPlatform uncaughtExceptionHandler(UncaughtExceptionHandler ueh) {
|
||||
setUncaughtExceptionHandler(ueh);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfPlatform group(ThreadGroup group) {
|
||||
this.group = Objects.requireNonNull(group);
|
||||
|
@ -208,7 +208,7 @@ class ThreadBuilders {
|
|||
* ThreadBuilder.OfVirtual implementation.
|
||||
*/
|
||||
static final class VirtualThreadBuilder
|
||||
extends BaseThreadBuilder<OfVirtual> implements OfVirtual {
|
||||
extends BaseThreadBuilder implements OfVirtual {
|
||||
private Executor scheduler;
|
||||
|
||||
VirtualThreadBuilder() {
|
||||
|
@ -221,6 +221,30 @@ class ThreadBuilders {
|
|||
this.scheduler = Objects.requireNonNull(scheduler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfVirtual name(String name) {
|
||||
setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfVirtual name(String prefix, long start) {
|
||||
setName(prefix, start);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfVirtual inheritInheritableThreadLocals(boolean inherit) {
|
||||
setInheritInheritableThreadLocals(inherit);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfVirtual uncaughtExceptionHandler(UncaughtExceptionHandler ueh) {
|
||||
setUncaughtExceptionHandler(ueh);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread unstarted(Runnable task) {
|
||||
Objects.requireNonNull(task);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue