I have a very simple springboot application as follow :
import org.springframework.web.bind.annotation.*;
import java.util.LinkedList;
import java.util.Queue;
@RestController
public class QuestionController {
private Queue<String> queue = new LinkedList<>();
@PostMapping("/api/foos")
@ResponseBody
public String addFoo(@RequestParam(name = "id") String fooId) {
queue.add(fooId);
return "ID: " + fooId + " " + queue.size();
}
@GetMapping("/api/get")
@ResponseBody
public String getFoo() {
return queue.peek() + " " + queue.size();
}
}
There is a queue in this web service.
The post method will add something to the queue
The get method will remove something from the queue.
I have assurance the number of get is greater than the number of post.
I would like to prevent the app from shutting down if there is still something in the queue!
What I tried:
From Springboot 2.3, there is a property for graceful shutdown.
However, after tring setting the property server.shutdown=graceful
to true, the app could still be shut with something in the queue.
Question:
How to prevent the app from shutting down if there is still something inside the queue, while utilizing the concept of the graceful shutdown.