0

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.

4

1 に答える 1

2

はい、非同期呼び出しに JMS を使用できます。それが最善の方法です。

スレッドを起動して、自分で管理することもできます。これは一般的に推奨されません。スレッド プールを適切に管理し、どのスレッドに時間がかかるかを追跡するには、多くのオーバーヘッド コードが必要です。

于 2012-05-03T22:30:40.340 に答える