Implementation and configuration of spring timing tasks (2)

Next, I thought my implementation method was very simple. When I was ready to write (I), I checked how others realized scheduled tasks. It's good not to check. This check found that there are simpler ones. So there will be this article.

This paper mainly discusses the implementation of simple scheduled tasks when the spring project is built.

In the previous article, we implemented the "simplest" scheduled task, where we are based on the dependency of Maven management package, relying on the following two packages:

Originally, I thought that the new method might not be needed, so I tried to comment it out, so this happened:

Obviously I'm wrong. Let's start:

The first step is to add the two packages listed above to Maven's POM file;

The second step is to add a namespace in the spring configuration management XML header (this is what most documents write, but no formal statement has been found. If there is one, I will modify this term, which is used for the time being)

Step 3: configure the contents related to scheduled tasks in the spring configuration file

Step 4: complete the business logic implementation class:

This method is simpler than configuration, but I think the configuration method will be more flexible. Of course, there are many implementation methods. We only discuss the simplest implementation, which is obviously the simplest implementation I have seen.

Start the service, let's see the effect:

That's about it, but here I found that I ran the code twice at the same time mentioned at the end of the last article. I have to see it again. If you have any friends who know, please leave me a message!

The next article is about cron expressions

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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
分享
二维码
< <上一篇
下一篇>>