SoFunction
Updated on 2025-04-05

Detailed explanation of the function of adding timed tasks in Java JFinal framework

Today, the function of adding timed tasks to the JFinal framework project was implemented. Here is a summary:

1. Add task scheduling plugin to BaseConfig's configPlugin

public class BaseConfig extends JFinalConfig {
    ……
    /**
      * Configuration plug-in
      */
    public void configPlugin(Plugins me) {
        ……
        // Task Scheduling Plugin        (new Cron4jPlugin(("conf/")));
    }
}

Configuration

# What tasks need to be scheduled? Multiple task names can be separated by commascron4j = queryCron,queryCrontwo

# cron expression debugging task = 00 00 * * *
# Whether the debugging thread is set to a daemon thread, the default value is true, and the daemon thread will be automatically closed when tomcat is closed = true
# Class file for executing tasks = 
# Whether the task is valid, the default value is true. If it is false, the task is invalid and will not be called = false

#Generate data table timing tasks for the current month# cron expression debugging task = 00 01 * * *
# Whether the debugging thread is set to a daemon thread, the default value is true, and the daemon thread will be automatically closed when tomcat is closed = true
# Class file for executing tasks = 
# Whether the task is valid, the default value is true. If it is false, the task is invalid and will not be called = true

cron expression:00 01 * * * Corresponds to: minute time day month week day, week day, this expression means that this task will be executed at any month, any day, or 01:00.

3. Implement timing task task

public class QueryIndexTask implements ITask {

    @Override
    public void run() {
        ("The mission has begun");
    }

    @Override
    public void stop() {
        ("The mission is over");
    }
}

This is the end of this article about the detailed explanation of the function of adding timed tasks in the Java JFinal framework. For more related content on adding timed tasks in Java JFinal, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!