https://github.com/rbiedrawa/spring-graceful-shutdown-poc
This repository demonstrates how to configure graceful shutdown of Network and default TaskExecutor threads in Spring Boot application.
https://github.com/rbiedrawa/spring-graceful-shutdown-poc
async graceful-shutdown gradle spring-async spring-boot
Last synced: about 15 hours ago
JSON representation
This repository demonstrates how to configure graceful shutdown of Network and default TaskExecutor threads in Spring Boot application.
- Host: GitHub
- URL: https://github.com/rbiedrawa/spring-graceful-shutdown-poc
- Owner: rbiedrawa
- License: mit
- Created: 2021-06-11T03:42:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-31T02:05:12.000Z (over 3 years ago)
- Last Synced: 2025-01-26T18:17:20.209Z (9 months ago)
- Topics: async, graceful-shutdown, gradle, spring-async, spring-boot
- Language: Java
- Homepage:
- Size: 64.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Spring Boot graceful shutdown (PoC)
This repository demonstrates how to configure graceful shutdown of Network and default TaskExecutor threads in Spring
Boot application.## Getting Started
### Prerequisites
* Java 11
### Usage
* Start application in IDE.
* Create async tasks via curl:
```shell
curl -X POST --location "http://localhost:8080/tasks"
```* Terminate application while tasks are still running in background threads.
* Check application logs to see if application shutdown gracefully. Sample output below:
```shell
# 2021-06-11 06:39:16.977 INFO [nio-8080-exec-1] com.rbiedrawa.app.tasks.TaskController : Creating task 1
# 2021-06-11 06:39:16.990 INFO [ my-thread-1] com.rbiedrawa.app.tasks.TaskService : Starting long running process id 1
# 2021-06-11 06:39:17.609 INFO [nio-8080-exec-2] com.rbiedrawa.app.tasks.TaskController : Creating task 2
# 2021-06-11 06:39:17.609 INFO [ my-thread-2] com.rbiedrawa.app.tasks.TaskService : Starting long running process id 2
# 2021-06-11 06:39:20.103 INFO [extShutdownHook] o.s.b.w.e.tomcat.GracefulShutdown : Commencing graceful shutdown. Waiting for active requests to complete
# 2021-06-11 06:39:20.107 INFO [tomcat-shutdown] o.s.b.w.e.tomcat.GracefulShutdown : Graceful shutdown complete
# 2021-06-11 06:39:20.163 INFO [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
# 2021-06-11 06:39:26.989 INFO [ my-thread-1] com.rbiedrawa.app.tasks.TaskService : Completed long running process id 1
# 2021-06-11 06:39:27.609 INFO [ my-thread-2] com.rbiedrawa.app.tasks.TaskService : Completed long running process id 2
#
# Process finished with exit code 130 (interrupted by signal 2: SIGINT)
```*** *Using graceful shutdown with your IDE may not work properly if it does not send a proper SIGTERM signal. Refer to
the documentation of your IDE for more details.*## Important Endpoints
| Name | Endpoint |
| -------------:|:--------:|
| `Spring Boot Application` | http://localhost:8080 |
| `Create Async Task - Endpoint` | http://localhost:8080/tasks |## References
* [Spring Boot Docs - Graceful shutdown](https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.graceful-shutdown)
## License
Distributed under the MIT License. See `LICENSE` for more information.