I need to fetch some data from external service. I dont know yet whether that service will be a simple servlet, or may be web-service, or something else. Lets assume that by now external service is just a simple servlet which returns JSON after HTTP request. Also I get some data of the same kind from my database.
I need to write a code which calls that service and searches the database and returns the joined results from both datasources.
The external service may not be available, so I have to write something to avoid waiting forever for the non-working external service.
I use EJB3 and Hibernate wrapped in JPA for database access.
My pseudocode for a straightforward solution looks like:
Thread t = new Thread()
{
public void run() {
*send HTTP GET*
*process results*
*populate some field with data received*
}
}
t.run();
*get data from db*
*place countDownLatch here with count = 2 and await timeout*
*join the results*
How would you go about implementing this task? Is my solution ok?