Jetty9 - Set stopTimeout to zero by default, and setting defaults for threaded component that need a non-zero stop timeout to stop properly.

This commit is contained in:
Simone Bordet 2012-08-10 16:45:05 +02:00
parent 136f7924fd
commit c3dfd0c653
5 changed files with 13 additions and 3 deletions

View File

@ -268,6 +268,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
public ManagedSelector(int id)
{
_id = id;
setStopTimeout(5000);
}
@Override

View File

@ -15,6 +15,7 @@ package org.eclipse.jetty.server;
import java.io.IOException;
import java.net.Socket;
import java.nio.channels.AsynchronousCloseException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.Executor;
@ -172,7 +173,12 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
for (Thread thread : _acceptors)
{
if (thread != null)
{
thread.interrupt();
long stopTimeout = getStopTimeout();
if (stopTimeout > 0)
thread.join(stopTimeout);
}
}
super.doStop();
@ -273,9 +279,10 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co
{
accept(_acceptor);
}
catch (IOException | InterruptedException e)
catch (AsynchronousCloseException | InterruptedException e)
{
logger.ignore(e);
break;
}
catch (Throwable e)
{

View File

@ -304,7 +304,6 @@ public class Server extends HandlerWrapper implements Attributes
MultiException mex=new MultiException();
// TODO: review this logic ...
long stopTimeout = getStopTimeout();
if (stopTimeout>0)
{

View File

@ -41,7 +41,7 @@ public abstract class AbstractLifeCycle implements LifeCycle
private final Object _lock = new Object();
private final int __FAILED = -1, __STOPPED = 0, __STARTING = 1, __STARTED = 2, __STOPPING = 3;
private volatile int _state = __STOPPED;
private long _stopTimeout = 10000;
private long _stopTimeout = 0;
protected void doStart() throws Exception
{

View File

@ -81,6 +81,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
setMinThreads(minThreads);
setMaxThreads(maxThreads);
setMaxIdleTimeMs(maxIdleTimeMs);
setStopTimeout(5000);
}
@Override
@ -110,6 +111,8 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
super.doStop();
long start=System.currentTimeMillis();
// TODO: review the stop logic avoiding sleep(1), and eventually using Thread.interrupt() + thread.join()
// let jobs complete naturally for a while
while (_threadsStarted.get()>0 && (System.currentTimeMillis()-start) < (getStopTimeout()/2))
Thread.sleep(1);