How to set timeout for Jersey REST web services?
I would like to know how to set a timeout for a REST web service with Jersey, and being able to catch it within the service. I've read some approaches to achieve this, such as calling another service after the timeout to check if the current service is active, or verifying application credentials, etc.
I'd rather not to follow these approaches. In fa开发者_开发知识库ct, I would like to know if is possible to set a listener to the HTTP request, or to the service itself, that would execute some procedure if the timeout is reached.
I suppose that creating a thread within the service body to act as listener could be a solution, but I'd like to know if there is a solution closer to Jersey.
I'm pretty sure that Jersey like many other api's has client timeout functionality built in. Don't want to give you loads of code so you can check out these posts Not sure I remember correctly but I think you can set it using this clint api through setReadTimeout and setConnectTimeout*
https://jersey.java.net/apidocs/1.1.1-ea/jersey/com/sun/jersey/api/client/Client.html
精彩评论