430654 - closing client connections can hang worker threads.
Prettified usage of NonBlockingThread and added Javadocs.
This commit is contained in:
parent
1089a33578
commit
342c97d8ba
|
@ -204,7 +204,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
|||
ManagedSelector selector = newSelector(i);
|
||||
_selectors[i] = selector;
|
||||
selector.start();
|
||||
execute(selector);
|
||||
execute(new NonBlockingThread(selector));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -476,13 +476,8 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
|||
public void run()
|
||||
{
|
||||
_thread = Thread.currentThread();
|
||||
final String name = _thread.getName();
|
||||
String name = _thread.getName();
|
||||
try
|
||||
{
|
||||
NonBlockingThread.runAsNonBlocking(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
_thread.setName(name + "-selector-" + SelectorManager.this.getClass().getSimpleName()+"@"+Integer.toHexString(SelectorManager.this.hashCode())+"/"+_id);
|
||||
LOG.debug("Starting {} on {}", _thread, this);
|
||||
|
@ -490,8 +485,6 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
|||
select();
|
||||
runChanges();
|
||||
}
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
LOG.debug("Stopped {} on {}", _thread, this);
|
||||
|
|
|
@ -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<>();
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue