I tried using the Callable option to set a timeout on a function call, while setting the timeout duration itself in Spring Boot's configuration file (spring.mvc.async.request-timeout).
The code does return after the set timeout, but the problem is that the function itself continues the execution.
I don't have an access to that function's source code, as it's a third party libaray, so I don't have a way to set an interruption-check in that code.
Is there a way to force the termination of the function / the thread once the timeout is over? Am I using the wrong path here and is there another way to achieve this goal?
An example of the current code, which "returns" after the timeout, but doesn't really stop the execution of that code in the background:
@RequestMapping(value = "/api/test", method = RequestMethod.POST, produces = "application/json")
public Callable<ResponseEntity<String>> test(@RequestParam(...) Boolean bbb) {
return new Callable<ResponseEntity<String>>() {
@Override
public ResponseEntity<String> call() throws Exception {
try {
<POTENTIALLY LONG 3RD-PARTY FUNCTION CALL HERE>
.....
} catch (Exception e) {
return new ResponseEntity<String>("..." }", HttpStatus.BAD_REQUEST);
}
}
};
}
Thank you.