Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove VirtualExecutorUtil.java #7263

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.helidon.common.configurable;

import java.lang.System.Logger.Level;
Expand All @@ -22,6 +23,7 @@
import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -216,7 +218,7 @@ private static class MethodInvocationImpl implements ExecutorServiceSupplierObse
private final Class<?> type;

private static final LazyValue<ExecutorService> VIRTUAL_EXECUTOR_SERVICE = LazyValue
.create(VirtualExecutorUtil::executorService);
.create(Executors::newVirtualThreadPerTaskExecutor);

static MethodInvocationImpl create(String displayName, String description, String methodName) {
ExecutorService executorService = VIRTUAL_EXECUTOR_SERVICE.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022 Oracle and/or its affiliates.
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,8 @@
package io.helidon.common.configurable;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -72,7 +74,7 @@ private ThreadPoolSupplier(Builder builder) {
this.growthThreshold = builder.growthThreshold;
this.growthRate = builder.growthRate;
this.rejectionHandler = builder.rejectionHandler == null ? DEFAULT_REJECTION_POLICY : builder.rejectionHandler;
this.useVirtualThreads = builder.useVirtualThreads || builder.virtualThreadsEnforced;
this.useVirtualThreads = builder.useVirtualThreads;
ObserverManager.registerSupplier(this, name, "general", useVirtualThreads);
}

Expand Down Expand Up @@ -111,10 +113,8 @@ public static ThreadPoolSupplier create(String name) {

ExecutorService getThreadPool() {
if (useVirtualThreads) {
if (VirtualExecutorUtil.isVirtualSupported()) {
LOGGER.log(System.Logger.Level.TRACE, "Using unbounded virtual executor service for pool " + name);
return ObserverManager.registerExecutorService(this, VirtualExecutorUtil.executorService());
}
ThreadFactory factory = Thread.ofVirtual().name(name + "-", 0).factory();
return ObserverManager.registerExecutorService(this, Executors.newThreadPerTaskExecutor(factory));
}

ThreadPool result = ThreadPool.create(name,
Expand Down Expand Up @@ -165,7 +165,6 @@ public static final class Builder implements io.helidon.common.Builder<Builder,
private ThreadPool.RejectionHandler rejectionHandler = DEFAULT_REJECTION_POLICY;
private String name;
private boolean useVirtualThreads;
private boolean virtualThreadsEnforced;

private Builder() {
}
Expand All @@ -186,13 +185,6 @@ public ThreadPoolSupplier build() {
rejectionHandler = DEFAULT_REJECTION_POLICY;
}

if (virtualThreadsEnforced) {
if (!VirtualExecutorUtil.isVirtualSupported()) {
throw new IllegalStateException("Virtual threads are required, yet not available on this JVM. "
+ "Please use a Loom build.");
}
}

return new ThreadPoolSupplier(this);
}

Expand Down

This file was deleted.