I'm trying to implement a tcp client based on classic I/O
. In order to reduce negotioation latency I decided to create a connection pool to the server which looks like this:
BlockingQueue<Socket> connections = //
Every time a thread trying to communicate with the server it does the following:
Socket s = null;
try{
Socket s = connections.take();
if(s.isClosed())
s = //create a new connection
//send data to the server
} finally {
if(!connections.offer(s))
throw new IllegalStateException();
}
I'm not sure if it's common to do like this. At least I have not heard about such an approach. Can someone suggest something that's more common.