Reputation: 1303
I have a simple java web service. I want to have the web service be threaded, where each call to a web method gets its own thread to do processing. The processing takes a long time and I don't want it to block, prevent other calls to the web method from happening. Instead, I want the web method to only create the Threads and for the Thread itself to respond/return a value to the client after its done processing. Is that possible?
EDIT:
Here's a semi-pseudocode of what I have right now:
@WebService(endpointInterface="Service")
public class ServiceImpl {
public ServiceImpl()
{
// Initialization
}
public String GetResult(input)
{
// Does long processing
return Result;
}
}
What I want to do is instead of GetResult() doing the long processing, I want it only spawn the Runnable that will do the long processing and have GetResult() return and ready to service another request. I also want the Runnable to respond to the waiting client.
EDIT 2:
I just realized that I'm asking a silly question. I'm fairly new to implement WS's. I had thought that WS's only took one request at a time sequentially. I didn't know each request is already automatically threaded.
Upvotes: 0
Views: 3694
Reputation: 3634
Yes, you can use JMS for asynchronous calls. That's the best way.
You could also fire up a thread, and manage them yourself. That's not generally recommended. Good management of the thread pool, and keeping track of which threads might be taking to long requires a lot of overhead code.
Upvotes: 2