Detailed introduction of scheduled task taskscheduler in spring

@H_ 502_ 2 @ Preface

As we all know, after spring version 3.0, it comes with a timed task tool, which is simple and convenient to use. It can dynamically change the execution state without configuration files. You can also set a scheduled task using a cron expression.

@H_ 502_ 2 @ the class to be executed should implement the runnable interface

@H_ 502_ 2@TaskScheduler Interface

Taskscheduler is an interface. Six methods are defined under the taskscheduler interface

1、schedule(Runnable task,Trigger trigger);

Specify a trigger to perform a scheduled task. You can use cronrigger to specify cron expressions to perform scheduled tasks

2、schedule(Runnable task,Date startTime);

Specify a specific time point to execute a scheduled task. You can dynamically specify the time and start the task. Execute only once. (it's much easier to use than timer. I wish I had found this interface earlier...)

3、scheduleAtFixedRate(Runnable task,long period);

Execute immediately, cycle the task, and specify an execution cycle (in milliseconds)

@H_ 502_ 2@PS : no matter whether the previous cycle is completed or not, the next cycle will start to execute at the time

4、scheduleAtFixedRate(Runnable task,Date startTime,long period);

Specify the time to start execution, cycle the task, and specify an interval period (in milliseconds)

@H_ 502_ 2@PS : no matter whether the previous cycle is completed or not, the next cycle will start to execute at the time

5、scheduleWithFixedDelay(Runnable task,long delay);

Execute immediately, cycle the task, and specify an interval period (in milliseconds)

@H_ 502_ 2@PS : wait for the delay time after the execution of the previous cycle, and start the execution of the next cycle

6、scheduleWithFixedDelay(Runnable task,long delay);

Specify the time to start execution, cycle the task, and specify an interval period (in milliseconds)

@H_ 502_ 2@PS : wait for the delay time after the execution of the previous cycle, and start the execution of the next cycle

@H_ 502_ 2@TaskScheduler There are five implementation classes under

1、ConcurrentTaskScheduler

Executes the task with the current thread. If the task is simple, you can directly use this class to execute it. Fast and convenient.

@H_ 502_ 2@PS : This is a single threaded run

2、DefaultManagedTaskScheduler

Execute tasks with the current thread, which is a subclass of concurrenttaskscheduler and adds JNDI support. The same usage as concurrent task scheduler requires JNDI and can be set separately

3、ThreadPoolTaskScheduler

The default implementation class of taskscheduler interface, multi-threaded scheduled task execution. You can set the number of execution thread pools (one thread by default).

@H_ 502_ 2@PS :

4、TimerManagerTaskScheduler

I haven't used this, so I don't have a specific understanding. I'll add it when I have time. Welcome to add if you have any understanding.

@H_ 502_ 2 @ summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>