From d69d386f7d02088c33b6caa33932b31573a942f6 Mon Sep 17 00:00:00 2001 From: orbiter Date: Wed, 3 Oct 2007 00:21:53 +0000 Subject: [PATCH] added additional forced client connection closing if a specific number of simultanous connections is reached the limit is currently set to 64 connections git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4129 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/http/httpc.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.java index 35e2f35d0..e589d7e10 100644 --- a/source/de/anomic/http/httpc.java +++ b/source/de/anomic/http/httpc.java @@ -56,6 +56,7 @@ import java.net.SocketException; import java.net.UnknownHostException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.Date; import java.util.Enumeration; @@ -111,6 +112,7 @@ public final class httpc { private static final HashMap reverseMappingCache = new HashMap(); private static final HashSet activeConnections = new HashSet(); // all connections are stored here and deleted when they are finished private static final long minimumTime_before_activeConnections_cleanup = 600000; + private static final int activeConnections_maximum = 64; public static final connectionTimeComparator connectionTimeComparatorInstance = new connectionTimeComparator(); private static int objCounter = 0; // will be increased with each object and is use to return a hash code @@ -431,8 +433,20 @@ public final class httpc { // try to find and close all connections that did not find a target server and are idle waiting for a server socket httpc[] a = allConnections(); // put set into array to avoid ConcurrentModificationExceptions + int tbd = 0; int c = 0; - for (int i = 0; i < a.length; i++) { + if (a.length > activeConnections_maximum) { + // delete some connections; choose the oldest + Arrays.sort(a, httpc.connectionTimeComparatorInstance); + tbd = a.length - activeConnections_maximum; + for (int i = 0; i < tbd; i++) { + if (a[i] != null) { + a[i].close(); + c++; + } + } + } + for (int i = tbd; i < a.length; i++) { httpc clientConnection = a[i]; if ((clientConnection != null) && (clientConnection.initTime != Long.MAX_VALUE) &&