< prev index next > src/java.base/share/classes/java/lang/ThreadBuilders.java
Print this page
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadFactory;
import jdk.internal.misc.Unsafe;
import jdk.internal.invoke.MhUtil;
+ import jdk.internal.reflect.CallerSensitive;
+ import jdk.internal.reflect.Reflection;
import jdk.internal.vm.ContinuationSupport;
/**
* Defines static methods to create platform and virtual thread builders.
*/
private Executor scheduler;
VirtualThreadBuilder() {
}
- // invoked by tests
- VirtualThreadBuilder(Executor scheduler) {
- if (!ContinuationSupport.isSupported())
- throw new UnsupportedOperationException();
- this.scheduler = Objects.requireNonNull(scheduler);
- }
-
@Override
public OfVirtual name(String name) {
setName(name);
return this;
}
@Override
public ThreadFactory factory() {
return new VirtualThreadFactory(scheduler, name(), counter(), characteristics(),
uncaughtExceptionHandler());
}
+
+ @CallerSensitive
+ @Override
+ public OfVirtual scheduler(Executor scheduler) {
+ Class<?> caller = Reflection.getCallerClass();
+ caller.getModule().ensureNativeAccess(OfVirtual.class, "scheduler", caller, false);
+ if (!ContinuationSupport.isSupported()) {
+ throw new UnsupportedOperationException();
+ }
+ this.scheduler = Objects.requireNonNull(scheduler);
+ return this;
+ }
}
/**
* Base ThreadFactory implementation.
*/
< prev index next >