Skip to content

Commit

Permalink
Remove VirtualExecutorUtil.java (#7263)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-langer committed Jul 31, 2023
1 parent 1146a19 commit 6473a4f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 116 deletions.
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.

0 comments on commit 6473a4f

Please sign in to comment.