1

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?

KutaBeach
  • 1,445
  • 21
  • 43
  • 1
    Look at this: http://stackoverflow.com/questions/3816286/multithreading-in-a-stateless-session-bean# it could help. What I would do is setting a timeout for the external HTTP GET call so you don't get waiting indefinitely. Regards – pvm14 Apr 04 '13 at 21:29

0 Answers0