【问题标题】:How to know the running scheduled jobs in spring boot application?如何知道 Spring Boot 应用程序中正在运行的计划作业?
【发布时间】:2023-04-10 23:15:01
【问题描述】:

我们可以在 Spring Boot 应用程序中使用 @Scheduled 轻松安排作业。

有没有办法使用任何休息端点知道当前正在运行的计划作业?

【问题讨论】:

    标签: spring-boot spring-scheduled


    【解决方案1】:

    是的,您需要将 Spring 引导执行器作为您的依赖项之一。然后您可以使用 scheduletasks 端点来检查计划任务:

    https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

    只需将以下内容添加到您的 pom.xml 中

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    

    端点位于 /actuator/scheduledtasks

    【讨论】:

    • 在 spring boot 1.5.18.RELEASE 中是否可用?
    • 它在 1.5.18.RELEASE 中可用。
    • 我相信是这样,但是路径的执行器部分是在 2.0 中引入的,所以它只是 /scheduledtasks
    • 我得到 404
    • 当你启动你的 Spring Boot 应用程序时,所有端点都应该在控制台中列出(从 2.0 开始,它们不再列出)。我不记得 1.5.18 的确切端点(我们现在使用的是 2.17.RELEASE 版本),但如果您阅读控制台输出,您应该会发现它列在那里。
    猜你喜欢
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    相关资源
    最近更新 更多