Search code examples
javamultithreadingjakarta-eeglassfish-3

Fast loading data from two sql servers


I need to load and merge data from two different sql servers (JDBC) and give the result via REST to the client.

Instead of loading first data a and then data b I would like to start loading data a then start loading data b and wait for both to finish and then merge the data. In Standard Java I would use Callable Threads to do this. But what can I do in Glassfish (Java EE).

What'm I allowed to do?


Solution

  • Within a Java EE app server, the standard way to do something like this would be to use an asynchronous method invocation (new in Java EE 6 I believe). Your "main" call would in turn call 2 asynchronous EJB methods which would then both run in parallel. Your main call would wait for them both to complete and then merge the results and return them to the caller.