seguin 02/01/09 19:03:59 Modified: jk/java/org/apache/ajp/tomcat4 Ajp13Processor.java Log: a quick patch to attempt to shorten shutdown time, plus some additional logging. the idea is simple: set a flag when the processor is handling a request, then when stopping, only wait on the worker thread if a request is currently being handled. this patch won't make a difference if the connector is busy and there are a bunch of processors currently handling requests, but it will make a difference if the connector is not busy. Revision Changes Path 1.6 +78 -14 jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Processor.java Index: Ajp13Processor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Processor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Ajp13Processor.java 20 Dec 2001 17:44:51 -0000 1.5 +++ Ajp13Processor.java 10 Jan 2002 03:03:59 -0000 1.6 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Processor.java,v 1.5 2001/12/20 17:44:51 jfclere Exp $ - * $Revision: 1.5 $ - * $Date: 2001/12/20 17:44:51 $ + * $Header: /home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/ajp/tomcat4/Ajp13Processor.java,v 1.6 2002/01/10 03:03:59 seguin Exp $ + * $Revision: 1.6 $ + * $Date: 2002/01/10 03:03:59 $ * * ==================================================================== * @@ -102,12 +102,35 @@ /** * @author Kevin Seguin - * @version $Revision: 1.5 $ $Date: 2001/12/20 17:44:51 $ + * @version $Revision: 1.6 $ $Date: 2002/01/10 03:03:59 $ */ final class Ajp13Processor implements Lifecycle, Runnable { + /** + * A simple class to provide synchronized access + * to a boolean. + */ + private class Bool { + + private boolean b = false; + + Bool() { + } + + Bool(boolean b) { + this.b = b; + } + + synchronized boolean value() { + return b; + } + + synchronized void set(boolean b) { + this.b = b; + } + } // ----------------------------------------------------------- Constructors @@ -207,7 +230,12 @@ /** * The shutdown signal to our background thread */ - private boolean stopped = false; + private Bool stopped = new Bool(true); + + /** + * Are we currently handling a request? + */ + private Bool handlingRequest = new Bool(false); /** @@ -256,7 +284,7 @@ available = true; notifyAll(); - if ((debug >= 1) && (socket != null)) + if ((debug > 0) && (socket != null)) logger.log(" An incoming request is being assigned"); } @@ -284,7 +312,7 @@ available = false; notifyAll(); - if ((debug >= 1) && (socket != null)) + if ((debug > 0) && (socket != null)) logger.log(" The incoming request has been awaited"); return (socket); @@ -332,7 +360,7 @@ } boolean moreRequests = true; - while (moreRequests) { + while (moreRequests && !stopped.value()) { int status = 0; try { @@ -340,6 +368,13 @@ } catch (IOException e) { logger.log("process: ajp13.receiveNextRequest", e); } + + if (stopped.value()) { + if (debug > 0) { + logger.log("process: received request, but we're stopped"); + } + break; + } if( status==-2) { // special case - shutdown @@ -356,6 +391,9 @@ break; try { + // set flag + handlingRequest.set(true); + // set up request request.setAjpRequest(ajpRequest); request.setResponse(response); @@ -365,14 +403,23 @@ response.setRequest(request); response.setStream(output); - if (this.debug > 0) { + if (debug > 0) { logger.log("invoking..."); } + connector.getContainer().invoke(request, response); + if (debug > 0) { + logger.log("done invoking, finishing request/response...."); + } + response.finishResponse(); request.finishRequest(); + if (debug > 0) { + logger.log("finished handling request."); + } + } catch (Exception e) { logger.log("process: invoke", e); } @@ -384,6 +431,9 @@ // recycle ajp13 object ajp13.recycle(); + + // reset flag + handlingRequest.set(false); } try { @@ -399,7 +449,9 @@ } socket = null; - logger.log("process: done"); + if (debug > 0) { + logger.log("process: done"); + } } @@ -413,7 +465,7 @@ public void run() { // Process requests until we receive a shutdown signal - while (!stopped) { + while (!stopped.value()) { // Wait for the next socket to be assigned Socket socket = await(); @@ -443,11 +495,12 @@ logger.log(sm.getString("ajp13Processor.starting")); + stopped.set(false); thread = new Thread(this, threadName); thread.setDaemon(true); thread.start(); - if (debug >= 1) + if (debug > 0) logger.log(" Background thread has been started"); } @@ -460,11 +513,22 @@ logger.log(sm.getString("ajp13Processor.stopping")); - stopped = true; + stopped.set(true); assign(null); synchronized (threadSync) { try { - threadSync.wait(5000); + if (handlingRequest.value()) { + if (debug > 0) { + logger.log + ("currentling handling a request, so waiting...."); + } + threadSync.wait(5000); + } else { + if (debug > 0) { + logger.log + ("not currently handling a request, not waiting."); + } + } } catch (InterruptedException e) { ; }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>