我需要从外部服务获取一些数据。我还不知道该服务是一个简单的servlet,还是web服务或其他东西。让我们假设现在外部服务只是一个简单的servlet,它在HTTP请求之后返回JSON。 我也从我的数据库中获得了一些相同类型的数据。
我需要编写一个调用该服务的代码并搜索数据库并返回两个数据源的连接结果。
外部服务可能不可用,所以我必须写一些东西以避免永远等待不工作的外部服务。
我使用JPA中包含的EJB3和Hibernate进行数据库访问。
我的直接解决方案的伪代码如下:
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*
您将如何实施此任务? 我的解决方案好吗?