Scheduled Tasks (scheduledtasks)
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: 1222
{
"cron" : [ {
"runnable" : {
"target" : "com.example.Processor.processOrders"
},
"expression" : "0 0 0/3 1/1 * ?",
"nextExecution" : {
"time" : "2026-01-22T08:59:59.999378744Z"
}
} ],
"fixedDelay" : [ {
"runnable" : {
"target" : "com.example.Processor.purge"
},
"initialDelay" : 0,
"interval" : 5000,
"nextExecution" : {
"time" : "2026-01-22T08:01:08.923881265Z"
},
"lastExecution" : {
"time" : "2026-01-22T08:01:03.917105200Z",
"status" : "SUCCESS"
}
} ],
"fixedRate" : [ {
"runnable" : {
"target" : "com.example.Processor.retrieveIssues"
},
"initialDelay" : 10000,
"interval" : 3000,
"nextExecution" : {
"time" : "2026-01-22T08:01:13.912992202Z"
}
} ],
"custom" : [ {
"runnable" : {
"target" : "com.example.Processor$CustomTriggeredRunnable@691ff4fe"
},
"trigger" : "com.example.Processor$CustomTrigger@3d426638",
"lastExecution" : {
"exception" : {
"message" : "Failed while running custom task",
"type" : "java.lang.IllegalStateException"
},
"time" : "2026-01-22T08:01:03.951028888Z",
"status" : "ERROR"
}
} ]
}
响应结构
响应包含应用程序计划任务的详细信息。下表描述了响应的结构:
| 路径(Path) | 类型(Type) | 描述(Description) |
|---|---|---|
cron | Array | Cron 任务(如果有)。 |
cron.[].runnable.target | String | 将要执行的目标。 |
cron.[].nextExecution.time | String | 下一次计划执行的时间。 |
cron.[].expression | String | Cron 表达式。 |
fixedDelay | Array | 固定延迟任务(如果有)。 |
fixedDelay.[].runnable.target | String | 将要执行的目标。 |
fixedDelay.[].initialDelay | Number | 首次执行前的延迟时间(以毫秒为单位)。 |
fixedDelay.[].nextExecution.time | String | 下一次计划执行的时间(如果已知)。 |
fixedDelay.[].interval | Number | 上一次执行结束与下一次执行开始之间的间隔(以毫秒为单位)。 |
fixedRate | Array | 固定速率任务(如果有)。 |
fixedRate.[].runnable.target | String | 将要执行的目标。 |
fixedRate.[].interval | Number | 每次执行开始之间的时间间隔(以毫秒为单位)。 |
fixedRate.[].initialDelay | Number | 首次执行前的延迟时间(以毫秒为单位)。 |
fixedRate.[].nextExecution.time | String | 下一次计划执行的时间(如果已知)。 |
custom | Array | 使用自定义触发器的任务(如果有)。 |
custom.[].runnable.target | String | 将要执行的目标。 |
custom.[].trigger | String | 任务的触发器。 |
*.[].lastExecution | Object | 该任务的上一次执行记录(如果有)。 |
*.[].lastExecution.status | String | 上一次执行的状态(STARTED、SUCCESS、ERROR)。 |
*.[].lastExecution.time | String | 上一次执行的时间。 |
*.[].lastExecution.exception.type | String | 任务抛出的异常类型(如果有)。 |
*.[].lastExecution.exception.message | String | 任务抛出的异常消息(如果有)。 |