0
# Scheduling and Background Tasks
1
2
Quarkus provides cron-like scheduling capabilities with programmatic scheduler access and comprehensive lifecycle event handling for background task management.
3
4
## Scheduling Annotations
5
6
### @Scheduled Annotation
7
8
```java { .api }
9
@Target(ElementType.METHOD)
10
@Retention(RetentionPolicy.RUNTIME)
11
public @interface Scheduled {
12
String cron() default "";
13
String every() default "";
14
long delay() default -1;
15
TimeUnit delayUnit() default TimeUnit.MILLISECONDS;
16
String identity() default "";
17
boolean skipExecutionIf() default false;
18
}
19
```
20
21
Schedules method execution based on cron expressions or intervals.
22
23
### Scheduler Interface
24
25
```java { .api }
26
public interface Scheduler {
27
void pause();
28
void resume();
29
boolean isRunning();
30
List<Trigger> getScheduledJobs();
31
}
32
```
33
34
Programmatic scheduler control interface.
35
36
**Usage Example:**
37
```java
38
@ApplicationScoped
39
public class TaskScheduler {
40
41
@Scheduled(every = "30s")
42
public void performCleanup() {
43
System.out.println("Performing cleanup task");
44
}
45
46
@Scheduled(cron = "0 0 2 * * ?") // Daily at 2 AM
47
public void generateReports() {
48
System.out.println("Generating daily reports");
49
}
50
}
51
```