0

asmx Web サービスがあります。WSDL を使用してクライアントをテストする必要があります。クライアント側非同期マッピングのコードを正常に実装しました。問題は、クライアントがサーバーに対して複数の同時要求を行う方法を理解できないことです。インターフェイスを見たことがありFutureますが、それを使用して同時呼び出しを行う方法がわかりません。

private void callAsyncCallback(String encodedString, String key) {

    DataManipulation service = new DataManipulation();

    try { // Call Web Service Operation(async. callback)
        DataManipulationSoap port = service.getDataManipulationSoap12();
        // TODO initialize WS operation arguments here
        AsyncHandler<GetDataResponse> asyncHandler =
                new AsyncHandler<GetDataResponse>() {

                    @Override
                    public void handleResponse(Response<GetDataResponse> response) {
                        try {
                            // TODO process asynchronous response here
                            System.out.println("Output at:::   " + new Date().toString());
                            System.out.println("************************Result = " + response.get().getGetDataResult());
                        } catch (Exception ex) {
                            // TODO handle exception
                        }
                    }
                };
        Future<? extends Object> result = port.getDataAsync(encodedString,key, asyncHandler);
        while (!result.isDone()) {
            // do something
        }
    } catch (Exception ex) {
        // TODO handle custom exceptions here
    }

}

while(!result.isDone())ループ内で何かを実行できることはわかっていますが、ここで Web サービスを再度呼び出すにはどうすればよいでしょうか?

目的は、複数のファイルを Web サービスに送信する必要があることです。WS はこれらのファイルに対して何らかの操作を実行し、何らかの結果を返します。クライアントがすべてのファイルを同時に送信して、所要時間を大幅に短縮したいと考えています。コードでメソッドをcallAsyncCallback複数回呼び出してみましたが、最初の呼び出しがクライアントに戻ったときにのみ次の行に進みます。

編集

ExecutorService へのポインタを教えてもらえますか? invokeAll のようないくつかのオプションについて読んだことがありますが、それを JAX-WS に関連付けることができません。どんな助けでも大歓迎です。

ありがとう

4

1 に答える 1

0

すべてのコードで Future の代わりにListenableFutureを常に使用することを強くお勧めします。

例:

   ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
    ListenableFuture<Explosion> explosion = service.submit(new Callable<Explosion>() {
      public Explosion call() {
        return pushBigRedButton();
      }
    });
    Futures.addCallback(explosion, new FutureCallback<Explosion>() {
      // we want this handler to run immediately after we push the big red button!
      public void onSuccess(Explosion explosion) {
        walkAwayFrom(explosion);
      }
      public void onFailure(Throwable thrown) {
        battleArchNemesis(); // escaped the explosion!
      }
    });
于 2013-10-23T12:32:00.750 に答える