定时任务 (scheduledtasks)

scheduledtasks 端点提供有关应用程序定时任务的信息。

获取定时任务

要获取定时任务,向 /actuator/scheduledtasks 发送 GET 请求,如下面的基于 curl 的示例所示:

$ curl 'http://localhost:8080/actuator/scheduledtasks' -i -X GET

响应结果类似于以下内容:

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 1207

{
  "cron" : [ {
    "runnable" : {
      "target" : "com.example.Processor.processOrders"
    },
    "expression" : "0 0 0/3 1/1 * ?",
    "nextExecution" : {
      "time" : "2025-05-25T12:59:59.999308Z"
    }
  } ],
  "fixedDelay" : [ {
    "runnable" : {
      "target" : "com.example.Processor.purge"
    },
    "initialDelay" : 0,
    "interval" : 5000,
    "lastExecution" : {
      "status" : "SUCCESS",
      "time" : "2025-05-25T10:03:21.704617Z"
    },
    "nextExecution" : {
      "time" : "2025-05-25T10:03:26.706930Z"
    }
  } ],
  "fixedRate" : [ {
    "runnable" : {
      "target" : "com.example.Processor.retrieveIssues"
    },
    "initialDelay" : 10000,
    "interval" : 3000,
    "nextExecution" : {
      "time" : "2025-05-25T10:03:31.704280Z"
    }
  } ],
  "custom" : [ {
    "runnable" : {
      "target" : "com.example.Processor$CustomTriggeredRunnable@11ef3bee"
    },
    "trigger" : "com.example.Processor$CustomTrigger@1c018f41",
    "lastExecution" : {
      "status" : "ERROR",
      "exception" : {
        "message" : "Failed while running custom task",
        "type" : "java.lang.IllegalStateException"
      },
      "time" : "2025-05-25T10:03:22.033344Z"
    }
  } ]
}

响应结构

响应包含应用程序定时任务的详细信息。 下表描述了响应的结构:

Path Type Description

cron

Array

Cron tasks, if any.

cron.[].runnable.target

String

Target that will be executed.

cron.[].nextExecution.time

String

Time of the next scheduled execution.

cron.[].expression

String

Cron expression.

fixedDelay

Array

Fixed delay tasks, if any.

fixedDelay.[].runnable.target

String

Target that will be executed.

fixedDelay.[].initialDelay

Number

Delay, in milliseconds, before first execution.

fixedDelay.[].nextExecution.time

String

Time of the next scheduled execution, if known.

fixedDelay.[].interval

Number

Interval, in milliseconds, between the end of the last execution and the start of the next.

fixedRate

Array

Fixed rate tasks, if any.

fixedRate.[].runnable.target

String

Target that will be executed.

fixedRate.[].interval

Number

Interval, in milliseconds, between the start of each execution.

fixedRate.[].initialDelay

Number

Delay, in milliseconds, before first execution.

fixedRate.[].nextExecution.time

String

Time of the next scheduled execution, if known.

custom

Array

Tasks with custom triggers, if any.

custom.[].runnable.target

String

Target that will be executed.

custom.[].trigger

String

Trigger for the task.

*.[].lastExecution

Object

Last execution of this task, if any.

*.[].lastExecution.status

String

Status of the last execution (STARTED, SUCCESS, ERROR).

*.[].lastExecution.time

String

Time of the last execution.

*.[].lastExecution.exception.type

String

Exception type thrown by the task, if any.

*.[].lastExecution.exception.message

String

Message of the exception thrown by the task, if any.