Java: establishing socket connection pool -
I have a client-server application using Java sockets. So far, it works in the following way:
Customer opens a socket connection on the server. The socket handler thread of the server puts a new socket on a LinkedBlockingQueue. A worker takes a socket from the thread queue and reads an object from the stream (the client sends the object on the server) and writes back an answer to the client and closes the socket.
But now I want to create a connection pool so that the connections can be kept open but I still want LinkedBlockingQueud.
My idea is that each new connection is placed in a queue, call it openSocketQueue, and then sockethandler thread (or some other thread) runs on open sourceQueE and checks whether New data is available (without reading data). If the data is available, then it removes the socket from the queue and puts it on the linking block. The socket is not closed after the worker has finished but put it back on the open source code.
Is it fair? How does a socket repeat again, is there any new data availble in an efficient way?
Anyway, I can not convert to NIO because I do not have time for it.
You are completely confused.
Connection pooling is applied On Customer: Instead of calling new socket ()
, you see in the collection imposed by Target IP: Port ; To return the connection to the pool instead of closing; And you add a thread that closes the socket in the pool for a very long time, e.g. 15 seconds
All you need on the server is a thread per connection which escapes requests to EOS, as we have discussed in you. None of these available () / linked blocking queue
stuff.
Comments
Post a Comment