开发者

Java web service and multithreading

开发者 https://www.devze.com 2023-02-14 15:56 出处:网络
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 the

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 serv开发者_开发知识库ice the parent of the threads ? (The use of a queueing technology for this solution is not an option).

Thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消