edit-icon download-icon

Simple job examples

Last Updated: Feb 01, 2018

This topic introduces how to use SchedulerX to implement some simple jobs.

  1. Output Hello World! every second. (Time expression: 0/1 ?)

    1. public class HelloWorldJobProcessor implements ScxSimpleJobProcessor {
    2. public ProcessResult process(ScxSimpleJobContext context) {
    3. System.out.println("Hello World!");
    4. return new ProcessResult(true);//true indicates that the job runs successfully, and false indicates that the job fails to run.
    5. }
    6. }
  2. Run a Shell script to delete log files at 01:00 every day. (Time expression: 0 0 1 ?)

    1. public class ExecuteShellJobProcessor implements ScxSimpleJobProcessor {
    2. public ProcessResult process(ScxSimpleJobContext context) {
    3. try {
    4. Runtime.getRuntime().exec("rm -rf /home/admin/logs/*.log");
    5. } catch (IOException e) {
    6. e.printStackTrace();
    7. }
    8. return new ProcessResult(true);//true indicates that the job runs successfully, and false indicates that the job fails to run.
    9. }
    10. }
  3. Display a birthday reminder once every year. (Time expression: 0 0 0 11 11 ?) *)

    1. public class BirthdayJobProcessor implements ScxSimpleJobProcessor {
    2. public ProcessResult process(ScxSimpleJobContext context) {
    3. // The birthday reminder service logic is omitted.
    4. return new ProcessResult(true);//true indicates that the job runs successfully, and false indicates that the job fails to run.
    5. }
    6. }
Thank you! We've received your feedback.