368240 - Better handling of locally created ThreadPool.

This commit is contained in:
Simone Bordet 2012-01-10 17:44:57 +01:00
parent 297625b446
commit 3a30b4b7a5
1 changed files with 22 additions and 31 deletions

View File

@ -16,13 +16,11 @@ package org.eclipse.jetty.client;
import java.io.IOException;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.net.ssl.SSLContext;
import org.eclipse.jetty.client.security.Authentication;
@ -133,7 +131,6 @@ public class HttpClient extends AggregateLifeCycle implements HttpBuffers, Attri
_sslContextFactory = sslContextFactory;
addBean(_sslContextFactory);
addBean(_buffers);
setBufferTypes();
}
/* ------------------------------------------------------------------------------- */
@ -169,16 +166,6 @@ public class HttpClient extends AggregateLifeCycle implements HttpBuffers, Attri
*/
public ThreadPool getThreadPool()
{
if (_threadPool==null)
{
QueuedThreadPool pool = new QueuedThreadPool();
pool.setMaxThreads(16);
pool.setDaemon(true);
pool.setName("HttpClient");
_threadPool = pool;
addBean(_threadPool,true);
}
return _threadPool;
}
@ -419,8 +406,14 @@ public class HttpClient extends AggregateLifeCycle implements HttpBuffers, Attri
_idleTimeoutQ.setNow();
if (_threadPool==null)
getThreadPool();
{
QueuedThreadPool pool = new LocalQueuedThreadPool();
pool.setMaxThreads(16);
pool.setDaemon(true);
pool.setName("HttpClient");
_threadPool = pool;
addBean(_threadPool,true);
}
_connector=(_connectorType == CONNECTOR_SELECT_CHANNEL)?new SelectConnector(this):new SocketConnector(this);
addBean(_connector,true);
@ -439,7 +432,7 @@ public class HttpClient extends AggregateLifeCycle implements HttpBuffers, Attri
{
Thread.sleep(200);
}
catch (InterruptedException e)
catch (InterruptedException ignored)
{
}
}
@ -447,25 +440,21 @@ public class HttpClient extends AggregateLifeCycle implements HttpBuffers, Attri
});
}
/* ------------------------------------------------------------ */
long getNow()
{
return _timeoutQ.getNow();
}
/* ------------------------------------------------------------ */
@Override
protected void doStop() throws Exception
{
for (HttpDestination destination : _destinations.values())
{
destination.close();
}
_timeoutQ.cancelAll();
_idleTimeoutQ.cancelAll();
super.doStop();
_connector = null;
if (_threadPool instanceof LocalQueuedThreadPool)
removeBean(_threadPool);
removeBean(_connector);
}
@ -638,8 +627,6 @@ public class HttpClient extends AggregateLifeCycle implements HttpBuffers, Attri
_maxRedirects = redirects;
}
public int getRequestBufferSize()
{
return _buffers.getRequestBufferSize();
@ -902,4 +889,8 @@ public class HttpClient extends AggregateLifeCycle implements HttpBuffers, Attri
{
_sslContextFactory.setSecureRandomAlgorithm(secureRandomAlgorithm);
}
private static class LocalQueuedThreadPool extends QueuedThreadPool
{
}
}