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

Initial revision of Loom experiments #2224

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion etc/scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ mvn ${MAVEN_ARGS} --version
mvn ${MAVEN_ARGS} -f ${WS_DIR}/pom.xml \
clean install -e \
-Dmaven.test.failure.ignore=true \
-Pexamples,archetypes,spotbugs,javadoc,sources,tck,tests,pipeline
# -Pexamples,archetypes,spotbugs,javadoc,sources,tck,tests,pipeline
-Pexamples,archetypes,javadoc,sources,tck,tests,pipeline

#
# test running from jar file, and then from module path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
Expand Down Expand Up @@ -108,10 +109,34 @@ private void startServer(@Observes @Priority(PLATFORM_AFTER + 100) @Initialized(

// make sure all configuration is in place
if (null == jaxRsExecutorService) {
jaxRsExecutorService = ServerThreadPoolSupplier.builder()
Config serverConfig = config.get("server");
final java.lang.reflect.Method m;
if (serverConfig.get("virtual-threads").asBoolean().isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asBoolean().orElse(false) - what if virtual-threads: false - you would execute as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep; just a dumb typo in this draft PR

java.lang.reflect.Method temp = null;
try {
temp = Executors.class.getDeclaredMethod("newVirtualThreadExecutor");
} catch (final ReflectiveOperationException notLoomEarlyAccess) {
temp = null;
} finally {
m = temp;
}
} else {
m = null;
}
if (m != null) {
jaxRsExecutorService = () -> {
try {
return (ExecutorService) m.invoke(null);
} catch (final ReflectiveOperationException reflectiveOperationException) {
throw new IllegalStateException(reflectiveOperationException.getMessage(), reflectiveOperationException);
}
};
} else {
jaxRsExecutorService = ServerThreadPoolSupplier.builder()
.name("server")
.config(config.get("server.executor-service"))
.config(serverConfig.get("executor-service"))
.build();
}
}

// redirect to the first page when root is accessed (if configured)
Expand Down
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1411,5 +1411,34 @@ helidon-parent,helidon-dependencies,helidon-bom,helidon-se,helidon-mp,io.grpc,he
</plugins>
</build>
</profile>
<profile>
<id>loom</id>
<activation>
<jdk>16-loom</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
<release>16</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>16</source>
<release>16</release>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.helidon.webserver.jersey;

import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Supplier;

import io.helidon.common.configurable.ThreadPoolSupplier;
Expand All @@ -30,23 +32,51 @@ class AsyncExecutorProvider implements ExecutorServiceProvider {
private final Supplier<ExecutorService> executorServiceSupplier;

AsyncExecutorProvider(Supplier<ExecutorService> supplier) {
this.executorServiceSupplier = supplier;
this.executorServiceSupplier = Objects.requireNonNull(supplier);
}

static ExecutorServiceProvider create(Config config) {
return new AsyncExecutorProvider(ThreadPoolSupplier.builder()
Config asyncExecutorServiceConfig = config.get("async-executor-service");
final java.lang.reflect.Method m;
if (asyncExecutorServiceConfig.get("virtual-threads").asBoolean().isPresent()) {
java.lang.reflect.Method temp = null;
try {
temp = Executors.class.getDeclaredMethod("newVirtualThreadExecutor");
} catch (final ReflectiveOperationException notLoom) {
temp = null;
} finally {
m = temp;
}
} else {
m = null;
}
if (m != null) {
return new AsyncExecutorProvider(() -> {
try {
return (ExecutorService) m.invoke(null);
} catch (final ReflectiveOperationException reflectiveOperationException) {
throw new IllegalStateException(reflectiveOperationException.getMessage(), reflectiveOperationException);
}
});
} else {
return new AsyncExecutorProvider(ThreadPoolSupplier.builder()
.corePoolSize(1)
.maxPoolSize(10)
.prestart(false)
.threadNamePrefix("helidon-jersey-async")
.config(config.get("async-executor-service"))
.config(asyncExecutorServiceConfig)
.build());
}
}

static ExecutorServiceProvider create(ExecutorService executor) {
return new AsyncExecutorProvider(() -> executor);
}

static ExecutorServiceProvider create(Supplier<ExecutorService> executorServiceSupplier) {
return new AsyncExecutorProvider(executorServiceSupplier);
}

@Override
public ExecutorService getExecutorService() {
return executorServiceSupplier.get();
Expand Down