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) public ManagedSelector(int id)
{ {
_id = id; _id = id;
setStopTimeout(5000);
} }
@Override @Override

View File

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

View File

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

View File

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

View File

@ -81,6 +81,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
setMinThreads(minThreads); setMinThreads(minThreads);
setMaxThreads(maxThreads); setMaxThreads(maxThreads);
setMaxIdleTimeMs(maxIdleTimeMs); setMaxIdleTimeMs(maxIdleTimeMs);
setStopTimeout(5000);
} }
@Override @Override
@ -110,6 +111,8 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
super.doStop(); super.doStop();
long start=System.currentTimeMillis(); 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 // let jobs complete naturally for a while
while (_threadsStarted.get()>0 && (System.currentTimeMillis()-start) < (getStopTimeout()/2)) while (_threadsStarted.get()>0 && (System.currentTimeMillis()-start) < (getStopTimeout()/2))
Thread.sleep(1); Thread.sleep(1);