I have deployed a spring boot application (which has a spring boot scheduler running) in Azure app service, but when I stop the web app, its status shows `Stopped` but I can see the scheduler is till active.

Shreya Gupta 20 Reputation points
2024-03-25T10:04:26.0366667+00:00

I have deployed a spring boot application (which has a spring boot scheduler running) in Azure app service, but when I stop the web app, its status shows Stopped but I can see the scheduler is till active. But Scheduler ne stopped since the web app is stopped.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,878 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deepanshu katara 4,825 Reputation points
    2024-03-25T10:56:06.9433333+00:00

    Hi ,

    Check Shutdown Hook Implementation: Ensure that you have implemented a shutdown hook in your Spring Boot application to gracefully shut down the scheduler and any other background tasks when the application is stopped. You can use Spring's @PreDestroy annotation or implement DisposableBean interface to define cleanup logic that runs when the application context is closed.

    Please check this thread for more details https://stackoverflow.com/questions/26678208/spring-boot-shutdown-hook

    Kindly accept answer if it has helped , Thanks!


  2. brtrach-MSFT 15,251 Reputation points Microsoft Employee
    2024-03-28T00:41:10.13+00:00

    @Shreya Gupta It seems like you have already implemented the shutdown hook using the @PreDestroy annotation, but it is not working as expected. In that case, you can try setting the terminationGracePeriodSeconds property in your Azure Spring Apps configuration. This property specifies the duration in seconds after processes running in the app instance are sent a termination signal before they're forcibly halted. You can set this value longer than the expected cleanup time for your process. The value must be a non-negative integer. Setting the grace period to 0 stops the app instance immediately via the kill signal, with no opportunity to shut down. If the value is nil, Azure Spring Apps uses the default grace period, which is 90 seconds.

    You can also try setting the initialDelaySeconds property to a higher value in your health probe configuration. This property specifies the number of seconds after the app instance has started before probes are initiated. The default value is 0, the minimum value.

    If this answer was of any help, please consider accepting it as an answer or providing a positive survey. If you require further assistance, please reply via a comment to this answer so we can assist you further.