Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimone Bordet2014-03-27 14:37:23 +0000
committerSimone Bordet2014-03-27 14:37:23 +0000
commit342c97d8ba33512b87d79627c3dbfdf04f9fa42e (patch)
tree08ab6dea6a2ce8777894382f33dee4e2dc3cf1e2 /jetty-util
parent1089a335786734358fac49e64e26a35287fd0c48 (diff)
downloadorg.eclipse.jetty.project-342c97d8ba33512b87d79627c3dbfdf04f9fa42e.tar.gz
org.eclipse.jetty.project-342c97d8ba33512b87d79627c3dbfdf04f9fa42e.tar.xz
org.eclipse.jetty.project-342c97d8ba33512b87d79627c3dbfdf04f9fa42e.zip
430654 - closing client connections can hang worker threads.
Prettified usage of NonBlockingThread and added Javadocs.
Diffstat (limited to 'jetty-util')
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/thread/NonBlockingThread.java26
1 files changed, 22 insertions, 4 deletions
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/NonBlockingThread.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/NonBlockingThread.java
index 64076d3117..4fb75c7fb0 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/NonBlockingThread.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/NonBlockingThread.java
@@ -18,20 +18,38 @@
package org.eclipse.jetty.util.thread;
-public class NonBlockingThread
+/**
+ * Marker that wraps a Runnable, indicating that it is running in a thread that must not be blocked.
+ * <p />
+ * Client code can use the thread-local {@link #isNonBlockingThread()} to detect whether they are
+ * in the context of a non-blocking thread, and perform different actions if that's the case.
+ */
+public class NonBlockingThread implements Runnable
{
- private final static ThreadLocal<Boolean> __nonBlockingThread = new ThreadLocal<>();
+ private final static ThreadLocal<Boolean> __nonBlockingThread = new ThreadLocal<>();
+
+ /**
+ * @return whether the current thread is a thread that must not block.
+ */
public static boolean isNonBlockingThread()
{
return Boolean.TRUE.equals(__nonBlockingThread.get());
}
- public static void runAsNonBlocking(Runnable runnable)
+ private final Runnable delegate;
+
+ public NonBlockingThread(Runnable delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void run()
{
try
{
__nonBlockingThread.set(Boolean.TRUE);
- runnable.run();
+ delegate.run();
}
finally
{

Back to the top