My java application has to send messages(multithreaded) to a socket server. The application can send around 100-200 messages a second.
I want to know which is a better approach to do this ?
- Open a single client socket and send the message from all threads though this one socket. Disadvantages: Have to handle the reconnection logic on connection failure,may lose many messages when reconnection is in process.Thread safety, blocking ??
- Create a new client socket connection for each thread and close it after sending. Disadvantages: Even though I close the socket, the ports will wait till the TIME_WAIT period.
Which is a better practical approach ?