Job Scheduling - microfox-framework/MicroFox GitHub Wiki
In MicroFox, job scheduling is powered by Quartz Scheduler, a robust and flexible open-source job scheduling library for Java.
Jobs are scheduled using Cron expressions, allowing precise control over execution times, such as running a job every 5 minutes, daily at midnight, or even every few seconds.
🧠 Job Structure
A job is a class that implements org.quartz.Job
and contains a JobDataMap-
free execute
method:
public class ExampleJob implements Job {
@Override
public void execute(JobExecutionContext context) {
System.out.println("Running scheduled task at " + LocalDateTime.now());
}
}
🛠️ Scheduling a Job
You can schedule a job using a utility method like this:
public class MainClass {
public static void main(String[] args) {
job(ExampleJob.class, "*/3 * * * * ? *"); // Every 3 seconds
}
}
✅ Best Practices
- Make job classes stateless — avoid holding internal state across executions.
- Keep job logic short-running — long tasks should be delegated to asynchronous services.
- Use cron expressions carefully — an incorrect expression can easily overwhelm the system.
- Monitor and log executions — this helps with debugging and performance tracking.