@@ -167,7 +167,7 @@ public class SockIOPool {
167167 // set to hold sockets to close
168168 private Map <String ,Map <SockIO ,Long >> availPool ;
169169 private Map <String ,Map <SockIO ,Long >> busyPool ;
170- private Set <SockIO > deadPool ;;
170+ private Map <SockIO , Integer > deadPool ;;
171171
172172 // empty constructor
173173 protected SockIOPool () { }
@@ -498,7 +498,7 @@ public void initialize() {
498498 // pools
499499 availPool = new HashMap <String ,Map <SockIO ,Long >>( servers .length * initConn );
500500 busyPool = new HashMap <String ,Map <SockIO ,Long >>( servers .length * initConn );
501- deadPool = new HashSet <SockIO >();
501+ deadPool = new IdentityHashMap <SockIO , Integer >();
502502
503503 hostDeadDur = new HashMap <String ,Long >();
504504 hostDead = new HashMap <String ,Date >();
@@ -893,7 +893,7 @@ public SockIO getConnection( String host ) {
893893 }
894894 else {
895895 // add to deadpool for later reaping
896- deadPool .add ( socket );
896+ deadPool .put ( socket , new Integer ( 0 ) );
897897
898898 // remove from avail pool
899899 i .remove ();
@@ -1136,7 +1136,6 @@ protected void stopMaintThread() {
11361136 protected void selfMaint () {
11371137 log .debug ( "++++ Starting self maintenance...." );
11381138
1139-
11401139 // go through avail sockets and create sockets
11411140 // as needed to maintain pool settings
11421141 Map <String ,Set <SockIO >> newSockets =
@@ -1208,8 +1207,15 @@ protected void selfMaint() {
12081207 if ( (expire + maxIdle ) < System .currentTimeMillis () ) {
12091208 log .debug ( "+++ removing stale entry from pool as it is past its idle timeout and pool is over max spare" );
12101209
1211- // add to deadPool for later reaping
1212- deadPool .add ( socket );
1210+ if ( socket .isConnected () ) {
1211+ // add to busy pool
1212+ log .debug ( "++++ moving socket for host (" + host + ") to busy pool ... socket: " + socket );
1213+ addSocketToPool ( busyPool , host , socket );
1214+ }
1215+ else {
1216+ // add to deadPool for later reaping
1217+ deadPool .put ( socket , new Integer ( 0 ) );
1218+ }
12131219
12141220 // remove from the availPool
12151221 j .remove ();
@@ -1240,8 +1246,15 @@ protected void selfMaint() {
12401246 if ( (hungTime + maxBusyTime ) < System .currentTimeMillis () ) {
12411247 log .error ( "+++ removing potentially hung connection from busy pool ... socket in pool for " + (System .currentTimeMillis () - hungTime ) + "ms" );
12421248
1243- // add to deadPool for later reaping
1244- deadPool .add ( socket );
1249+ if ( socket .isConnected () ) {
1250+ // add to busy pool
1251+ log .debug ( "++++ moving socket for host (" + host + ") to busy pool ... socket: " + socket );
1252+ addSocketToPool ( busyPool , host , socket );
1253+ }
1254+ else {
1255+ // add to deadPool for later reaping
1256+ deadPool .put ( socket , new Integer ( 0 ) );
1257+ }
12451258
12461259 // remove from the busy pool
12471260 j .remove ();
@@ -1250,10 +1263,14 @@ protected void selfMaint() {
12501263 }
12511264 }
12521265
1253- // finally clean out the deadPool -- no need to lock as these are not in any pool
1254- for ( Iterator <SockIO > i = deadPool .iterator (); i .hasNext (); ) {
1266+ // finally clean out the deadPool
1267+ Set <SockIO > toClose ;
1268+ synchronized ( deadPool ) {
1269+ toClose = deadPool .keySet ();
1270+ deadPool = new IdentityHashMap <SockIO ,Integer >();
1271+ }
12551272
1256- SockIO socket = i . next ();
1273+ for ( SockIO socket : toClose ) {
12571274 try {
12581275 socket .trueClose ();
12591276 }
@@ -1262,8 +1279,6 @@ protected void selfMaint() {
12621279 log .error ( ex .getMessage (), ex );
12631280 socket = null ;
12641281 }
1265-
1266- i .remove ();
12671282 }
12681283
12691284 log .debug ( "+++ ending self maintenance." );
0 commit comments