4

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

2
  • 1
    Solves stackoverflow.com/questions/34852236/… your first problem? Commented May 17, 2016 at 17:59
  • I've tried that but it doesn't really work. Application crashes on an exception calling new HttpComponentsClientHttpRequestFactory(). I have found this stackoverflow.com/questions/13837012/…, where on the 3rd answer refers to Spring Boot as I need, and now the program runs, but it doesn't stop requests after the given milliseconds. Have I missed some configuration? Any further examples / code / help will be appreciated. Commented May 19, 2016 at 19:33

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Well, that's a nice trick, but it's a trick. It's not an infrastructural or framework way of doing this. Especially that my service has lots of APIs it introduces, and each such call should be wrapped to run within a thread or such. I thought of that, but I'm looking for something more fundamental.
@user2339344 Actually, that is a perfectly fundamental solution. It kicks in and does the job cleanly. Maybe add some ExecutorService logic for thread pooling or some fancy CompletableFuture usage but that's it. Messing with that SDK will most probably bring more problems.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.