For this shutdown hook I can one use case here I am stuck now. I am using quartz scheduler in my java application and when somehow due to jenkins nightly build my app can get stop signal any time. And at that point of time my quartz scheduler is busy doing some of job. The problem is quartz scheduler is creating it's own Threads without using any thread pool. And now if it's busy with job processing and someone stops my app in between then some of quartz jobs will be in incomplete state which stops my application to start again. Because whenever my application starts the quartz just check if previously any job was there which is incomplete then it ll try to complete those job but due to stop signal quarts was not able to add some entries in DB table and those entries are missing and quarts will not allow my app to start again.
Your demo is excellent but application would be multiple child processes and threads within the application at various/different places but they are all running on the same JVM....how are we going to resolve this issue?
we shall wait for all child processes to complete their processing. If they keep on running, we need to handle interrupted exception and shutdown gracefully by cleaning resources
Hi ! Can you tell how to invoke jvm hook in apache camel routes? Like , i have two routes. I am executing a one route and i stopped the flow. now i want the second route should always run? If you can tell such kind of implementation in spring, it will work for me
Thanks for helpful video. I have an app which expose single endpoint returning approved/denied as response. I want to gracefully shut down spring boot app if my endpoint returns denied for multiple calls for last 60 secs. Appreciate any inputs. Thanks in advance
Just tried the same in my machine with spring boot 2.3.1 release and Java 8 with the latest properties as per spring doc like server.shutdown as GRACEFUL and spring.lifecycle.timeout-per-shutdown-phase to 30s and its just stopping abruptly not like gracefully by waiting until current requests are processed
I would add for anyone using Eclipse as your IDE. This does not work if you run in the console. Not sure why. If you simply create the jar and run that with java -jar app.jar and hit cont-C while in sleep, this will work...
Not able to make the application run after importing, application runs if i change it to maven repo versions, then i don't get the graceful shutdown feature log
my BSNL broadband here at home is so slow and unreliable. it takes 4 hour to upload a 15min video. :( Stuck at hometown now. waiting for a new connection which is due after lockdown in India.
Thanks for this video. Also, if someone is like me using a older version of springboot, you can try this -stackoverflow.com/questions/22944144/programmatically-shut-down-spring-boot-application
Hello Sir, if app is running on Linux env. We can terminate using "kill PID" command i.e soft kill. How it is different from graceful shutdown feature added by Spring community in latest release. This links provides better solution to shutdown multithread app. www.baeldung.com/spring-boot-graceful-shutdown
Excelent content and great example of keeping your ongoing job even though the JVM was exited.
Thanks again!
It would be great to have you as a boss. Would enjoy coming to work everyday. Please do a more detailed version of batch.
For this shutdown hook I can one use case here I am stuck now. I am using quartz scheduler in my java application and when somehow due to jenkins nightly build my app can get stop signal any time. And at that point of time my quartz scheduler is busy doing some of job. The problem is quartz scheduler is creating it's own Threads without using any thread pool. And now if it's busy with job processing and someone stops my app in between then some of quartz jobs will be in incomplete state which stops my application to start again. Because whenever my application starts the quartz just check if previously any job was there which is incomplete then it ll try to complete those job but due to stop signal quarts was not able to add some entries in DB table and those entries are missing and quarts will not allow my app to start again.
Your demo is excellent but application would be multiple child processes and threads within the application at various/different places but they are all running on the same JVM....how are we going to resolve this issue?
we shall wait for all child processes to complete their processing. If they keep on running, we need to handle interrupted exception and shutdown gracefully by cleaning resources
great vid, can you explain why having thread pool in spring application makes it monolith?
Hi When enabled graceful shutdown and JVM shutdowns because of out of memory. Will it still try to wait for finishing off the active thread
Is there a more elegant way of waiting active threads to finish rather than using Thread.sleep?
You can use callables/Futures
Thanks and always your videos are very useful 👍
How to do graceful shutdown for spring boot with kafka streams?
The spring framework takes care of transactionality automatically.
Hi ! Can you tell how to invoke jvm hook in apache camel routes? Like , i have two routes. I am executing a one route and i stopped the flow. now i want the second route should always run? If you can tell such kind of implementation in spring, it will work for me
Hi,
How do you load the project from terminal to Intellij, using command?
Is it something, I need to configure?
Yes. You can use idea cli to launch intellij
Thanks for helpful video. I have an app which expose single endpoint returning approved/denied as response.
I want to gracefully shut down spring boot app if my endpoint returns denied for multiple calls for last 60 secs.
Appreciate any inputs. Thanks in advance
Thank you for the video. I have been looking for similar solution.
We could use executors.awaitTermination(5, TimeUnit.SECONDS) for executing tasks to be completed instead of getActiveCount and sleep.
Just tried the same in my machine with spring boot 2.3.1 release and Java 8 with the latest properties as per spring doc like server.shutdown as GRACEFUL and spring.lifecycle.timeout-per-shutdown-phase to 30s and its just stopping abruptly not like gracefully by waiting until current requests are processed
Any suggestions would be helpful
good stuff ! thanks for this Ajay
I would add for anyone using Eclipse as your IDE. This does not work if you run in the console. Not sure why. If you simply create the jar and run that with java -jar app.jar and hit cont-C while in sleep, this will work...
Not able to make the application run after importing, application runs if i change it to maven repo versions, then i don't get the graceful shutdown feature log
Hi ajay, when you will make QA session.....i guess this is the good time to take QA session.♥️
my BSNL broadband here at home is so slow and unreliable. it takes 4 hour to upload a 15min video. :(
Stuck at hometown now. waiting for a new connection which is due after lockdown in India.
Thanks for this video. Also, if someone is like me using a older version of springboot, you can try this -stackoverflow.com/questions/22944144/programmatically-shut-down-spring-boot-application
Instead you can make child thread call blocking.
Hello Sir, if app is running on Linux env. We can terminate using "kill PID" command i.e soft kill. How it is different from graceful shutdown feature added by Spring community in latest release.
This links provides better solution to shutdown multithread app. www.baeldung.com/spring-boot-graceful-shutdown
That link convers only for threads. It doesn't cover how you can clean or do additional tasks when shutdown is triggered (kill) in a spring boot way