Considering the following code:
@RestController
@RequestMapping("/timeout")
public class TestController {
@Autowired
private TestService service;
@GetMapping("/max10secs")
public String max10secs() {
//In some cases it can take more than 10 seconds
return service.call();
}
}
@Service
public class TestService {
public String call() {
//some business logic here
return response;
}
}
What I want to accomplish is that if the method call from the TestService takes more than 10 seconds I want to cancel it and generate a response with a HttpStatus.REQUEST_TIMEOUT code.