title: How to set a timeout on a Spring Boot REST API?
body: <p>I have some REST APIs that may take a while to execute, and I want to limit their execution duration. Preferably, if 30 seconds passed and the request didn't return, I would like to return a specific HTTP code / data and terminate that request completly.</p>
  
  <p>The current code:</p>
  
  <pre><code>@RestController
  @CrossOrigin(origins = {"*"}, maxAge = 4800, allowCredentials = "false")
  public class APIController {
  
  @RequestMapping(value = "/api/myapifunc", method = RequestMethod.POST, produces = "application/json")
  public ResponseEntity&lt;?&gt; optimize(@RequestParam(value="param1", defaultValue="")) {
      // Code here
  }
  </code></pre>