Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request timeout in Spring boot

I wish to set my Spring Boot server timeout, say to 15 seconds. To be clear: I wish that if my server fails to respond within 15 seconds it will return an error response (something like what happens in Heroku, only there it is 30 seconds). How can I do that?

My problem actually originates from the fact that this service is a gateway and it calls another service, which sometimes takes a long time to response, and I can't control that service's timeout. Since I'm using an SDK files to call that server, I can't control the outgoing calls. Is there a way I can globally set a timeout for all outgoing calls?

Thank you

like image 987
user2339344 Avatar asked Aug 31 '25 16:08

user2339344


1 Answers

You can wrap your library into a extra thread and then directly join on that thread with timeout. Example see http://www.journaldev.com/1024/java-thread-join-example-with-explanation

like image 65
GandalfIX Avatar answered Sep 02 '25 08:09

GandalfIX