views:

573

answers:

2

i want to write a java servlet that will be called by different users to do httpclient post content to another side via "POST" . i wanted to hear opinion from guru in this case, do my servlet need to use threadpool or something since i want to serve different users at the same time and each user is executing different httpclient post

A: 

Are your out-going POST requests going to be synchronous or asynchronous? That is: will the user-request for which the POST is being performed wait for the POST to complete?

Servlet engines already use separate threads for each request being concurrently handled, so if your outgoing POSTs are meant to be synchronous then you don't need to make your own thread pool. If they're asynchronous, however, you may want to have a producer consumer queue where requests "produce" a command to perform a POST, and a set of worker threads consume (and then perform) these commands.

Laurence Gonsalves
yes, need to wait for th post to complete and get respond from the post. also user need to do multiple post subsequencely
cometta
i gonna do asynchronous. do u have example demo on this?
cometta
Even if its asynchronous, you need not maintain a request pool for yourself.
Adeel Ansari
@Vinegar: I wasn't talking about a pool for the incoming requests, but rather a pool for handling outgoing requests.
Laurence Gonsalves
+1  A: 

You should read the HttpClient threading guide because you are in a multi-threaded environment within a servlet container.

Csaba_H