cleanup threadpool usage
This commit is contained in:
parent
b636c58af6
commit
6146f0cc9c
|
@ -27,7 +27,7 @@ public class HttpClientTransportOverHTTP extends AbstractHttpClientTransport
|
||||||
{
|
{
|
||||||
public HttpClientTransportOverHTTP()
|
public HttpClientTransportOverHTTP()
|
||||||
{
|
{
|
||||||
this(1);
|
this(Runtime.getRuntime().availableProcessors());
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpClientTransportOverHTTP(int selectors)
|
public HttpClientTransportOverHTTP(int selectors)
|
||||||
|
|
|
@ -424,7 +424,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
||||||
String name = _thread.getName();
|
String name = _thread.getName();
|
||||||
try
|
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);
|
LOG.debug("Starting {} on {}", _thread, this);
|
||||||
while (isRunning())
|
while (isRunning())
|
||||||
select();
|
select();
|
||||||
|
|
|
@ -177,7 +177,7 @@ public class ConnectHandler extends HandlerWrapper
|
||||||
|
|
||||||
protected SelectorManager newSelectorManager()
|
protected SelectorManager newSelectorManager()
|
||||||
{
|
{
|
||||||
return new Manager(getExecutor(), getScheduler(), 1);
|
return new ConnectManager(getExecutor(), getScheduler(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -429,10 +429,10 @@ public class ConnectHandler extends HandlerWrapper
|
||||||
dump(out, indent, getBeans(), TypeUtil.asList(getHandlers()));
|
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);
|
super(executor, scheduler, selectors);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,10 @@ import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import javax.servlet.AsyncContext;
|
import javax.servlet.AsyncContext;
|
||||||
import javax.servlet.ServletConfig;
|
import javax.servlet.ServletConfig;
|
||||||
import javax.servlet.ServletException;
|
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.HttpHeader;
|
||||||
import org.eclipse.jetty.http.HttpMethod;
|
import org.eclipse.jetty.http.HttpMethod;
|
||||||
import org.eclipse.jetty.http.HttpVersion;
|
import org.eclipse.jetty.http.HttpVersion;
|
||||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
|
||||||
import org.eclipse.jetty.util.HttpCookieStore;
|
import org.eclipse.jetty.util.HttpCookieStore;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
@ -206,7 +207,8 @@ public class ProxyServlet extends HttpServlet
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>maxThreads</td>
|
* <td>maxThreads</td>
|
||||||
* <td>256</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>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>maxConnections</td>
|
* <td>maxConnections</td>
|
||||||
|
@ -244,21 +246,30 @@ public class ProxyServlet extends HttpServlet
|
||||||
ServletConfig config = getServletConfig();
|
ServletConfig config = getServletConfig();
|
||||||
|
|
||||||
HttpClient client = newHttpClient();
|
HttpClient client = newHttpClient();
|
||||||
|
|
||||||
// Redirects must be proxied as is, not followed
|
// Redirects must be proxied as is, not followed
|
||||||
client.setFollowRedirects(false);
|
client.setFollowRedirects(false);
|
||||||
|
|
||||||
// Must not store cookies, otherwise cookies of different clients will mix
|
// Must not store cookies, otherwise cookies of different clients will mix
|
||||||
client.setCookieStore(new HttpCookieStore.Empty());
|
client.setCookieStore(new HttpCookieStore.Empty());
|
||||||
|
|
||||||
|
Executor executor;
|
||||||
String value = config.getInitParameter("maxThreads");
|
String value = config.getInitParameter("maxThreads");
|
||||||
if (value == null)
|
if (value == null || "-".equals(value))
|
||||||
value = "256";
|
{
|
||||||
QueuedThreadPool executor = new QueuedThreadPool(Integer.parseInt(value));
|
executor = (Executor)getServletContext().getAttribute("org.eclipse.jetty.server.Executor");
|
||||||
String servletName = config.getServletName();
|
}
|
||||||
int dot = servletName.lastIndexOf('.');
|
else
|
||||||
if (dot >= 0)
|
{
|
||||||
servletName = servletName.substring(dot + 1);
|
QueuedThreadPool qtp= new QueuedThreadPool(Integer.parseInt(value));
|
||||||
executor.setName(servletName);
|
String servletName = config.getServletName();
|
||||||
|
int dot = servletName.lastIndexOf('.');
|
||||||
|
if (dot >= 0)
|
||||||
|
servletName = servletName.substring(dot + 1);
|
||||||
|
qtp.setName(servletName);
|
||||||
|
executor=qtp;
|
||||||
|
}
|
||||||
|
|
||||||
client.setExecutor(executor);
|
client.setExecutor(executor);
|
||||||
|
|
||||||
value = config.getInitParameter("maxConnections");
|
value = config.getInitParameter("maxConnections");
|
||||||
|
|
|
@ -97,6 +97,8 @@ import org.eclipse.jetty.util.resource.Resource;
|
||||||
* <p>
|
* <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
|
* 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)}
|
* 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"
|
* @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;
|
Thread current_thread = null;
|
||||||
Context old_context = null;
|
Context old_context = null;
|
||||||
|
|
||||||
|
_attributes.setAttribute("org.eclipse.jetty.server.Executor",getServer().getThreadPool());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Set the classloader
|
// Set the classloader
|
||||||
|
|
Loading…
Reference in New Issue