Skip to content

Quarkus Scheduler

DodaTech 1 min read

In this tutorial, you'll learn about Fix Quarkus @Scheduled Not Running. We cover key concepts, practical examples, and best practices.

The Problem

@Scheduled methods in Quarkus do not run at the specified interval.

Quick Fix

Add @ApplicationScoped

Wrong:

@Scheduled(every = "5s")
public class CleanupTask { } // No scope

Output:

Task not started

Right:

@ApplicationScoped
public class CleanupTask {
    @Scheduled(every = "5s")
    public void run() { }
}

Output:

Task runs every 5 seconds

Use correct cron syntax

Wrong:

@Scheduled(cron = "0 0 * * * *")
// Wrong cron format

Output:

Task not scheduled

Right:

@Scheduled(cron = "0/5 * * * * ?")

Output:

Task scheduled every 5 seconds

Handle exceptions

Wrong:

@Scheduled(every = "5s")
public void run() { throw new RuntimeException(); } // Task stops

Output:

Execution halted

Right:

@Scheduled(every = "5s")
public void run() {
    try {
        // logic
    } catch (Exception e) {
        log.error("Task error", e);
    }
}

Output:

Task continues after errors

Prevention

  • Annotate task class with @ApplicationScoped
  • Use proper cron/every expressions
  • Catch exceptions inside scheduled methods

Common Mistakes with scheduler

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world QUARKUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does the task stop running?

Uncaught exceptions stop scheduled method execution in Quarkus.

This quick fix is part of the DodaTech Spring & JVM ecosystem series. Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro