This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new 2b3f0f0964 Improvements to French translations. (remm) 2b3f0f0964 is described below commit 2b3f0f09641e0d8504a114cf296a18d66039266b Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Dec 8 10:26:49 2023 +0000 Improvements to French translations. (remm) --- .../tomcat/util/threads/LocalStrings.properties | 2 + .../tomcat/util/threads/VirtualThreadExecutor.java | 62 +++++++++++++++++++++- webapps/docs/changelog.xml | 11 ++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/java/org/apache/tomcat/util/threads/LocalStrings.properties b/java/org/apache/tomcat/util/threads/LocalStrings.properties index 4b28c96f84..e6999e19e4 100644 --- a/java/org/apache/tomcat/util/threads/LocalStrings.properties +++ b/java/org/apache/tomcat/util/threads/LocalStrings.properties @@ -19,3 +19,5 @@ threadPoolExecutor.invalidKeepAlive=Core threads must have positive keep alive t threadPoolExecutor.queueFull=Queue capacity is full threadPoolExecutor.taskRejected=Task [{0}] rejected from [{1}] threadPoolExecutor.threadStoppedToAvoidPotentialLeak=Stopping thread [{0}] to avoid potential memory leaks after a context was stopped. + +vvirtualThreadExecutor.taskRejected=Task [{0}] rejected from [{1}] \ No newline at end of file diff --git a/java/org/apache/tomcat/util/threads/VirtualThreadExecutor.java b/java/org/apache/tomcat/util/threads/VirtualThreadExecutor.java index 93a00f8d42..01dc547d96 100644 --- a/java/org/apache/tomcat/util/threads/VirtualThreadExecutor.java +++ b/java/org/apache/tomcat/util/threads/VirtualThreadExecutor.java @@ -16,14 +16,24 @@ */ package org.apache.tomcat.util.threads; -import java.util.concurrent.Executor; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.AbstractExecutorService; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.TimeUnit; import org.apache.tomcat.util.compat.JreCompat; +import org.apache.tomcat.util.res.StringManager; /** * An executor that uses a new virtual thread for each task. */ -public class VirtualThreadExecutor implements Executor { +public class VirtualThreadExecutor extends AbstractExecutorService { + + private static final StringManager sm = StringManager.getManager(VirtualThreadExecutor.class); + + private CountDownLatch shutdown = new CountDownLatch(1); private final JreCompat jreCompat = JreCompat.getInstance(); @@ -35,6 +45,54 @@ public class VirtualThreadExecutor implements Executor { @Override public void execute(Runnable command) { + if (isShutdown()) { + throw new RejectedExecutionException( + sm.getString("virtualThreadExecutor.taskRejected", command.toString(), this.toString())); + } jreCompat.threadBuilderStart(threadBuilder, command); } + + @Override + public void shutdown() { + shutdown.countDown(); + } + + /** + * {@inheritDoc} + * <p> + * The VirtualThreadExecutor does not track in-progress tasks so calling this method is equivalent to calling + * {@link #shutdown()}. + */ + @Override + public List<Runnable> shutdownNow() { + shutdown(); + return Collections.emptyList(); + } + + @Override + public boolean isShutdown() { + return shutdown.getCount() == 0; + } + + /** + * {@inheritDoc} + * <p> + * The VirtualThreadExecutor does not track in-progress tasks so calling this method is equivalent to calling + * {@link #isShutdown()}. + */ + @Override + public boolean isTerminated() { + return isShutdown(); + } + + /** + * {@inheritDoc} + * <p> + * The VirtualThreadExecutor does not track in-progress tasks so calling this method is effectively waiting for + * {@link #shutdown()} to be called. + */ + @Override + public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { + return shutdown.await(timeout, unit); + } } \ No newline at end of file diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 01c72ce5eb..5a228d27a7 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -104,6 +104,17 @@ They eventually become mixed with the numbered issues (i.e., numbered issues do not "pop up" wrt. others). --> +<section name="Tomcat 10.1.18 (schultz)" rtext="in development"> + <subsection name="Coyote"> + <changelog> + <fix> + Refactor the <code>VirtualThreadExecutor</code> so that it can be used + by the NIO2 connector which was using platform threads even when + configured to use virtual threads. (markt) + </fix> + </changelog> + </subsection> +</section> <section name="Tomcat 10.1.17 (schultz)" rtext="in development"> <subsection name="Catalina"> <changelog> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org