"Distributed Task Scheduling Platform XXL-JOB"

Distributed task scheduling platform XXL-JOB
What is a scheduled task?
Specify a time to execute a task
. Java implements a timed task method?
1.Thread br/>2.timerTask 3.@Scheduled
annotation in springboot4.ScheduledExecutorService
timing thread in the thread pool
5.Quartz 1.Thread
public
class Demo01 {
static long count = 0;
public static void main(String[] args) {
Runnable runnable = new Runnable() {
br/>@Override
public void run() {
while (true) {
try {
Thread.sleep(1000);
count++;
System.out.println(count);
} catch (Exception e ) {
// TODO: handle exception
}
}
}
};
Thread thread = new Thread(runnable);
thread.start();
}
}
二.TimerTask
/**

  • Use the TimerTask class to implement timed tasks
    */
    public class Demo02 {
    static long count = 0;

    public static void main(String[] args) {
    TimerTask timerTask = new TimerTask() {

        @Override
        public void run() {
            count++;
            System.out.println(count);
        }
    };
    Timer timer = new Timer();
    // 天数
    long delay = 0;
    // 秒数
    long period = 1000;
    timer.scheduleAtFixedRate(timerTask, delay, period);

    }

}
3. ScheduledExecutorService
Using ScheduledExecutorService is introduced from java.util.concurrent of Java
JavaSE5 as a concurrent tool class, which is the most ideal way to implement timed tasks.
public class Demo003 {
public static void main(String[] args) {
Runnable runnable = new Runnable() {
public void run() {
// task to run goes here
System.out.println("Hello !!");
}
};
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
// The second parameter is the delay time of the first execution, and the third parameter is the interval time of scheduled execution
service.scheduleAtFixedRate(runnable, 1, 1, TimeUnit.SECONDS);
}
}
Four. Quartz
creates a quartz_demo project
to introduce maven dependencies
<dependencies>

org.quartz-scheduler quartz 2.2.1 org.quartz-scheduler quartz-jobs 2.2.1 withSchedule(SimpleScheduleBuilder.simpleSchedule()) .startAt(statTime) //Start at the current time by default.withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?")) //Execute once every two seconds.build(); / /5. Register tasks and timers scheduler.scheduleJob(jb, t); //6. Start the scheduler scheduler.start(); **Quartz expression** URL of the expression: http://cron.qqe2. com/ After entering![](http://i2.51cto.com/107?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) select An expression that is executed every 5 seconds, what needs to be configured by yourself? What problems will occur in timed tasks under distributed conditions? In the case of a distributed cluster, how to ensure that timed tasks are not repeatedly executed** Distributed timed task solutions: ①Using zookeeper to implement distributed lock shortcomings (need to create temporary nodes, and event notification is not easy to expand) ②Use configuration files to do After a switch disadvantage is released, it needs to be restarted ③The database is only constrained, and the disadvantage is low efficiency High concurrency 3. Resource not being utilized Using distributed task scheduling platform: 1. High availability 2. Load balancing 3. Fault tolerance mechanism 4. Cluster support 5. Management mechanism alarm scheme 6. Automatic management 7. Easy to learn, etc.** Introduction to XXLJOB** 1. Simple: support CRUD operations on tasks through web pages, easy to operate, and get started in one minute; 2. Dynamic: support dynamic modification of task status, suspend/resume tasks, and terminate running tasks , which takes effect immediately; 3. Scheduling center HA (centralized): The scheduling adopts a centralized design, and the "dispatching center" is implemented based on the cluster Quartz, which can ensure the HA of the scheduling center; 4. Executor HA (distributed): distributed execution of tasks, The task "executor" supports cluster deployment and can ensure task execution HA; 5. Task Failover: When the executor is deployed in a cluster, when the task routing policy selects "Failover", the executor will be smoothly switched to failover when the scheduling fails; 6. Consistency: "Scheduling Center" ensures the consistency of cluster distributed scheduling through DB locks, and one task scheduling will only trigger one execution; 7. Custom task parameters: support online configuration of scheduling task input parameters, which will take effect immediately; 8. Scheduling thread Pool: The multi-threading of the scheduling system triggers the scheduling operation to ensure that the scheduling is executed accurately and is not blocked; 9. Elastic capacity expansion and shrinkage: Once a new executor machine goes online or offline, the task will be reassigned the next time it is scheduled; 10. Mail Alarm: Support email alarm when the task fails, support configuring multiple email addresses to send alarm emails; 11. Status monitoring: Support real-time monitoring of task progress; 12. Rolling execution log: Support online viewing of scheduling results, and real-time viewing of executors in Rolling mode The complete execution log output; 13. GLUE: Provide Web IDE, support online development of task logic code, dynamic release, and real-time compilation to take effect, omitting the process of deployment and online. Supports historical version backtracking of 30 versions. 14. Data encryption: The communication between the scheduling center and the executor is encrypted to improve the security of scheduling information; 15. Task dependency: It supports the configuration of sub-task dependencies. When the execution of the parent task ends and the execution is successful, the sub-task will be actively triggered once. Task execution, multiple subtasks are separated by commas; 16. Push maven central warehouse: The latest stable version will be pushed to the maven central warehouse, which is convenient for users to access and use; 17. Task registration: The executor will automatically register tasks periodically , The dispatch center will automatically discover the registered tasks and trigger the execution. At the same time, it also supports manual entry of actuator addresses; 18. Routing strategy: Provides rich routing strategies when deploying actuator clusters, including: first, last, polling, random, consistent HASH, least frequently used, most recent 19. Running report: Support real-time viewing of running data, such as the number of tasks, scheduling times, number of executors, etc.; and scheduling reports, such as scheduling date distribution diagram, scheduling success distribution diagram, etc.; 20. Script task: Supports developing and running script tasks in GLUE mode, including scripts of Shell, Python, etc.; 21. Blocking processing strategy: The processing strategy when scheduling is too intensive for executors to process in time. The strategy includes: stand-alone serial (default) , Discard subsequent scheduling, overwrite previous scheduling; 22. Failure processing strategy; processing strategy when scheduling fails, strategies include: failure alarm (default), failure retry; 23. Sharded broadcast task: when the executor cluster is deployed, task routing When the strategy selects "sharding broadcast", a task scheduling will broadcast and trigger all executors in the corresponding cluster to execute a task, and pass the sharding parameters at the same time; sharding tasks can be developed according to the sharding parameters; 24. Dynamic sharding: sharding The slice broadcast task is sharded with the executor as the dimension, and supports the dynamic expansion of the executor cluster to dynamically increase the number of shards and perform business processing collaboratively; it can significantly improve the task processing capability and speed when performing large data volume business operations. 25. Event triggering: In addition to "Cron mode" and "task dependent mode" triggering task execution, event-based task triggering mode is supported. The dispatch center provides API services that trigger a single execution of tasks, which can be flexibly triggered according to business events. **XXLJOBGitHub address** https://github.com/xuxueli/xxl-job download![](http://i2.51cto.com/107?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i, color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) github top document http://www.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324737075&siteId=291194637