Assume there is a Java implementation of Object Pool and the objects are successfully connected TCP Sockets.
I keep a "Clean-Up" thread at the Pool level (ConnectionFactory) that checks every N mins that whether the pool is being idle for some M mins (i.e: last access is before M mins, here M>N).
And if so then close all the additional sockets until only the core number of sockets is left in the pool.
Now I need to trace and eliminate the abruptly closed sockets as well. It seems essential because I may close all the working ones and simply end up with a pool with abruptly closed sockets (closed at the other end).
Without a doubt, now I should look into the Socket level rather than the connection factory level.
I've done a research on 'tracing abruptly closed sockets in Java', 'cleaning connection pools' and there is nothing in the Java socket API unless we sent some ACK or KeepAliveChecks (per each socket). Which means I need to be performing this on every socket in a routine basis.
What is the best way (i.e: is there any other way) so I could end up keeping the good guys (well connected sockets) in my pool?
How to clean-up the abruptly closed sockets in my pool?
Interesting ,I just wrote a socket connection pool yesterday.
/** * @author:xingchaowang * @date: 8/14/2014. */
public class ConnectionPoolImpl implements ConnectionPool {
}