public final class StartupTask extends java.lang.Object implements java.lang.AutoCloseable
Reports the progress of a piece of work an application or plugin does while the application starts,
such as running database migrations or loading reference data, so that whatever follows the start can
show how far it has got: the startup progress page and report, or the startup endpoint of
Spring Boot Actuator.
A task has a description and, when it is known, the number of items of work it will do. Each item is begun with a name and ended when it is done:
try (StartupTask task = StartupTask.start(applicationContext, 'Loading reference data', files.size())) {
for (File file in files) {
task.startItem(file.name)
load(file)
task.endItem()
}
}
The task and its items are recorded as steps of the context's ApplicationStartup, named {
| Modifiers | Name | Description |
|---|---|---|
static java.lang.String |
DESCRIPTION_TAG |
The tag of a task's step that describes the task. |
static java.lang.String |
ITEM_STEP |
The name of the startup step that records one item of a task's work. |
static java.lang.String |
ITEM_TAG |
The tag of an item's step that names the item. |
static java.lang.String |
TASK_STEP |
The name of the startup step that records a task. |
static java.lang.String |
TOTAL_TAG |
The tag of a task's step that says how many items the task will do, when that is known. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
close()Ends the task, and the item of work in progress if there is one. |
|
public void |
endItem()Ends the item of work in progress, if there is one. |
|
public static boolean |
isRecorded(ApplicationContext context)Whether anything records the start of the given context, without which a task can skip work done only to report it. |
|
public static StartupTask |
start(ApplicationContext context, java.lang.String description, int total)Begins a task, recorded by the application startup of the given context. |
|
public static StartupTask |
start(ApplicationStartup startup, java.lang.String description, int total)Begins a task, recorded by the given application startup. |
|
public void |
startItem(java.lang.String name)Begins the next item of work, ending the one before if it has not been ended. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
The tag of a task's step that describes the task.
The name of the startup step that records one item of a task's work.
The tag of an item's step that names the item.
The name of the startup step that records a task.
The tag of a task's step that says how many items the task will do, when that is known.
Ends the task, and the item of work in progress if there is one.
Ends the item of work in progress, if there is one.
Whether anything records the start of the given context, without which a task can skip work done only to report it.
Begins a task, recorded by the application startup of the given context.
context - the context that is startingdescription - what the task does, such as Running database migrationstotal - how many items the task will do, or a negative number when that is not knownBegins a task, recorded by the given application startup.
startup - the application startup recording the startdescription - what the task does, such as Running database migrationstotal - how many items the task will do, or a negative number when that is not knownBegins the next item of work, ending the one before if it has not been ended.