Search code examples
javajakarta-eehttpurlconnectionjava-ee-6executorservice

What is the best way to make simultaneous httpurlconnection calls in a Java EE application


We have a requirement where we have to make four web service calls from our EJB. All these calls are independent of each other and should be made simultaneously.

Today we are using ExecutorService to make these calls. There is a timeout after which we shutdown the ExecutorService and check the responses.

I want to know if there is a better way to do the same?

P.S. We use websphere 8.5.0 which is a Java EE 6 server. I found there is ManagedExecutorService in Java EE 7. Is there anything in Java EE 6?


Solution

  • Have you considered using an asynchronous method on a Stateless Session Bean (with the @Asynchronous annotation)? This method would make the call to the web service and the app server (via the EJB pool) would be responsible for managing concurrency.

    See: https://docs.oracle.com/javaee/6/tutorial/doc/gkkqg.html