简体   繁体   中英

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?

PS 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM