xain
xain

Reputation: 13839

Java web service and multithreading

I need to implement a Java web service (on websphere) that in turn calls N other web services. I don't want to make it blocking so I was thinking in implementing a thread for each WS it call. Are there any caveats being a web service the parent of the threads ? (The use of a queueing technology for this solution is not an option).

Thanks

Upvotes: 0

Views: 3018

Answers (1)

hvgotcodes
hvgotcodes

Reputation: 120168

it is certainly doable. the only real caveat is that you are going to have to

1) make sure that all the information the threads need gets passed in. Depending on the technologies you are using, information gets bound to the current thread via ThreadLocal, so you need to make sure the children have everything they need.

2) Coordinating the responses. Might not be an issue, but if you need to coordinate the responses you will need to do something. Also, when the original web service call gets invoked, can you return a response immediately or do you need to wait till the other webservices are invoked?

3) Error conditions. If one of the child web service calls fails, what do you need to do? That depends on your requirements.

Note that invoking N webservices calls shouldn't take too long if N is small. I would try it synchronously before going thru the pain of getting an asynchronous solution, unless you are sure up front that this is not an option.

Upvotes: 1

Related Questions