cleanup threadpool usage

This commit is contained in:
Greg Wilkins 2013-09-30 14:07:17 +10:00
parent b636c58af6
commit 6146f0cc9c
5 changed files with 30 additions and 15 deletions

View File

@ -27,7 +27,7 @@ public class HttpClientTransportOverHTTP extends AbstractHttpClientTransport
{
public HttpClientTransportOverHTTP()
{
this(1);
this(Runtime.getRuntime().availableProcessors());
}
public HttpClientTransportOverHTTP(int selectors)

View File

@ -424,7 +424,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
String name = _thread.getName();
try
{
_thread.setName(name + "-selector-" + _id);
_thread.setName(name + "-selector-" + SelectorManager.this.getClass().getSimpleName()+"@"+Integer.toHexString(SelectorManager.this.hashCode())+"/"+_id);
LOG.debug("Starting {} on {}", _thread, this);
while (isRunning())
select();

View File

@ -177,7 +177,7 @@ public class ConnectHandler extends HandlerWrapper
protected SelectorManager newSelectorManager()
{
return new Manager(getExecutor(), getScheduler(), 1);
return new ConnectManager(getExecutor(), getScheduler(), 1);
}
@Override
@ -429,10 +429,10 @@ public class ConnectHandler extends HandlerWrapper
dump(out, indent, getBeans(), TypeUtil.asList(getHandlers()));
}
protected class Manager extends SelectorManager
protected class ConnectManager extends SelectorManager
{
private Manager(Executor executor, Scheduler scheduler, int selectors)
private ConnectManager(Executor executor, Scheduler scheduler, int selectors)
{
super(executor, scheduler, selectors);
}

View File

@ -28,8 +28,10 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.servlet.AsyncContext;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@ -47,7 +49,6 @@ import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.HttpCookieStore;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -206,7 +207,8 @@ public class ProxyServlet extends HttpServlet
* <tr>
* <td>maxThreads</td>
* <td>256</td>
* <td>The max number of threads of HttpClient's Executor</td>
* <td>The max number of threads of HttpClient's Executor. If not set, or set to the value of "-", then the
* Jetty server thread pool will be used.</td>
* </tr>
* <tr>
* <td>maxConnections</td>
@ -244,21 +246,30 @@ public class ProxyServlet extends HttpServlet
ServletConfig config = getServletConfig();
HttpClient client = newHttpClient();
// Redirects must be proxied as is, not followed
client.setFollowRedirects(false);
// Must not store cookies, otherwise cookies of different clients will mix
client.setCookieStore(new HttpCookieStore.Empty());
Executor executor;
String value = config.getInitParameter("maxThreads");
if (value == null)
value = "256";
QueuedThreadPool executor = new QueuedThreadPool(Integer.parseInt(value));
String servletName = config.getServletName();
int dot = servletName.lastIndexOf('.');
if (dot >= 0)
servletName = servletName.substring(dot + 1);
executor.setName(servletName);
if (value == null || "-".equals(value))
{
executor = (Executor)getServletContext().getAttribute("org.eclipse.jetty.server.Executor");
}
else
{
QueuedThreadPool qtp= new QueuedThreadPool(Integer.parseInt(value));
String servletName = config.getServletName();
int dot = servletName.lastIndexOf('.');
if (dot >= 0)
servletName = servletName.substring(dot + 1);
qtp.setName(servletName);
executor=qtp;
}
client.setExecutor(executor);
value = config.getInitParameter("maxConnections");

View File

@ -97,6 +97,8 @@ import org.eclipse.jetty.util.resource.Resource;
* <p>
* The maximum size of a form that can be processed by this context is controlled by the system properties org.eclipse.jetty.server.Request.maxFormKeys
* and org.eclipse.jetty.server.Request.maxFormContentSize. These can also be configured with {@link #setMaxFormContentSize(int)} and {@link #setMaxFormKeys(int)}
* <p>
* This servers executore is made available via a context attributed "org.eclipse.jetty.server.Executor".
*
* @org.apache.xbean.XBean description="Creates a basic HTTP context"
*/
@ -719,6 +721,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
Thread current_thread = null;
Context old_context = null;
_attributes.setAttribute("org.eclipse.jetty.server.Executor",getServer().getThreadPool());
try
{
// Set the classloader