Switch between Primary to Secondary source on Timeout in Java

自古美人都是妖i 提交于 2019-12-25 09:25:39

问题


I am developing an API which is dependent on two third party data sources - One is SOAP API (Primary source) and other is mssql database (secondary source). The problem is these two sources are not stable and which is impacting the API and other APIs in the eco-system due lot of thread waiting for the response for long ( its shooting JVM memory). I want to have an implementation which timeout primary data source after a certain amount of time if not responded and switches to secondary source and wait for response till timeout reaches otherwise show some error response.

I have gone through Java concurrent APIs. And found one solution of using ExecutorService#submit(callable) which return a Future and it has a Future#get(5, TimeUnit.SECONDS) method which will block until timeout reached.

  1. Is it recommended using this feature for such critical resource?
  2. Also are there chances that method execution did not start even if timeout reached? Does it guarantee that it would schedule it on priority?

Thanks

来源:https://stackoverflow.com/questions/44312834/switch-between-primary-to-secondary-source-on-timeout-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!