Steve, thank you for your response. Unfortunately, I don't believe this answers my question completely. Although it is true that on the server side I can have a pool of worker threads to handle socket requests, this only saves memory and resources with thread creation, not socket creation, which was my principal concern.
On the client side, whenever I tried to reuse a socket I created after opening and closing its streams, it would not work; i.e., the application would hang indefinitely. What you seem to be describing in your post is multiple clients reusing a pool of socket connections, which is not the case here, since all we have is a single client making socket connections to the server, one socket connection per business method request. There is no intermediary proxy service that is accepting requests from multiple clients here.
If I'm off the mark, please rectify my statements. Otherwise, I guess I'm still looking for a response that addresses <B>socket</B> reuse, not thread reuse.
Originally posted by Steve Granton:
Hi,
Not sure about part B as my solution is going to use RMI.
As for part A)
I think you're on the right lines as you realise that creating a new thread every time a a request is accepted can be quite a load on resources. Although threads are not as resource hungry as processes they still take time to create and tear down. In order to optimise this the server can maintain a pool of worker threads to which it passes a request for servicing. Once the request has been serviced the thread returns to the pool so that it can be reused.
In order to speed things up on the client-side you can implement a connection pool. A pool of socket connections to the server is created and when needed the client requests a new socket it obtains one from the pool. Once its finished it returns it to the pool for another client to use.
The client is usually unaware that they are using a connection pool as the pool wraps up the object the client is trying to get access to.
There is a javaworld article (http://www.javaworld.com/javaworld/jw-06-1998/jw-06-object-pool.html) which provides some advice on object pools.
I hope this helps,
Cheers,
Steve