Skip to content

Commit f08c779

Browse files
committed
Avoid virtualthread logic for ancient JDK17.
1 parent e91cefd commit f08c779

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

runtime/runtime_impl_jetty121/src/main/java/com/google/apphosting/runtime/http/JdkHttpApiHostClient.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.InputStream;
2929
import java.io.OutputStream;
3030
import java.io.UncheckedIOException;
31+
import java.lang.reflect.Method;
3132
import java.net.HttpURLConnection;
3233
import java.net.MalformedURLException;
3334
import java.net.SocketTimeoutException;
@@ -81,10 +82,20 @@ private JdkHttpApiHostClient(Config config, URL url, Executor executor) {
8182
@SuppressWarnings("AllowVirtualThreads")
8283
static JdkHttpApiHostClient create(String url, Config config) {
8384
try {
84-
Executor executor;
85+
Executor executor = null;
8586
if (Boolean.getBoolean("appengine.api.use.virtualthreads")) {
86-
executor = Executors.newVirtualThreadPerTaskExecutor();
87-
} else {
87+
try {
88+
Method newVirtualThreadPerTaskExecutor =
89+
Executors.class.getMethod("newVirtualThreadPerTaskExecutor");
90+
executor = (Executor) newVirtualThreadPerTaskExecutor.invoke(null);
91+
logger.atInfo().log("Using virtual threads for JdkHttpApiHostClient.");
92+
} catch (ReflectiveOperationException e) {
93+
logger.atInfo().log(
94+
"appengine.api.use.virtualthreads is true, but virtual threads are not available on"
95+
+ " this JDK. Falling back to thread pool for JdkHttpApiHostClient.");
96+
}
97+
}
98+
if (executor == null) {
8899
ThreadFactory factory =
89100
runnable -> {
90101
Thread t = new Thread(rootThreadGroup(), runnable);

0 commit comments

Comments
 (0)