1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-01-12 22:18:11 -05:00

Close idle connections to exchange after one minute

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@493 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-04-01 22:59:04 +00:00
parent 4fdca92f08
commit f10b0b6a85

View File

@ -25,6 +25,10 @@ public final class DavGatewayHttpClientFacade {
final static String IE_USER_AGENT = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
static MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager;
final static long ONE_MINUTE = 60000;
static Thread httpConnectionManagerThread = null;
static {
DavGatewayHttpClientFacade.start();
// force XML response with Internet Explorer header
@ -279,14 +283,14 @@ public final class DavGatewayHttpClientFacade {
* @return Http Exception
*/
public static HttpException buildHttpException(HttpMethod method) {
HttpException httpException = new HttpException();
httpException.setReasonCode(method.getStatusCode());
httpException.setReason(method.getStatusText());
return httpException;
return new HttpException(method.getStatusCode() + " " + method.getStatusText());
}
public static void stop() {
if (multiThreadedHttpConnectionManager != null) {
if (httpConnectionManagerThread != null) {
httpConnectionManagerThread.interrupt();
}
multiThreadedHttpConnectionManager.shutdown();
multiThreadedHttpConnectionManager = null;
}
@ -295,7 +299,23 @@ public final class DavGatewayHttpClientFacade {
public static void start() {
if (multiThreadedHttpConnectionManager == null) {
multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
multiThreadedHttpConnectionManager.setMaxConnectionsPerHost(10);
multiThreadedHttpConnectionManager.getParams().setDefaultMaxConnectionsPerHost(100);
httpConnectionManagerThread = new Thread("HttpConnectionManager") {
public void run() {
boolean terminated = false;
while (!terminated) {
try {
sleep(ONE_MINUTE);
} catch (InterruptedException e) {
terminated = true;
}
if (multiThreadedHttpConnectionManager != null) {
multiThreadedHttpConnectionManager.closeIdleConnections(ONE_MINUTE);
}
}
}
};
httpConnectionManagerThread.start();
}
}
}