diff options
author | Simone Bordet | 2014-03-27 14:37:23 +0000 |
---|---|---|
committer | Simone Bordet | 2014-03-27 14:37:23 +0000 |
commit | 342c97d8ba33512b87d79627c3dbfdf04f9fa42e (patch) | |
tree | 08ab6dea6a2ce8777894382f33dee4e2dc3cf1e2 /jetty-util | |
parent | 1089a335786734358fac49e64e26a35287fd0c48 (diff) | |
download | org.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.java | 26 |
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 { |