Get the App
SLTechnology News&Howtos  ›  Development  › 

@ Scheduled what if it doesn't execute?

Shulou Source: shulou.com Published: 2022-06-02 05:08:41 09月25日 Update

This article mainly explains "@ Scheduled does not implement how to do", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "@ Scheduled does not implement how to do" it!

@ Scheduled reason for not executing 1. Today I used @ Schedule to do a scheduled task.

I hope it will be executed at 1: 00 in the morning, with the following code

@ Servicepublic class ParseJsonService {@ Scheduled (cron = "0 01 * *?") Public void parseMongodbDataToJson () {}}

I came to the company the next day and found that it had not been implemented at all. And then start looking for problems.

two。 First came across a solution found.

It is said that it is the version of spring. I took a look at the scheduled tasks I used before. It is true that spring uses 4. 5%. So I changed the version of spring to 4 and found that it still didn't work.

3. There is also a version that says to be in spring.

Add an annotation driver to the configuration file of

And also add the default-lazy-init= "false" attribute, which says that spring is not allowed to load lazily, but it still doesn't work.

4. Also found that the version said to add @ Lazy (false) to Bean.

Let spring load the Bean at startup, but it still doesn't work.

The ultimate solution (for me, not necessarily for you, I use Spring version 3, not 4)

Step 1: add to the configuration file of spring

Step 2: add to the above Bean

@ EnableScheduling

The code is as follows:

@ Service@EnableSchedulingpublic class ParseJsonService {@ Scheduled (cron = "0 01 * *?") Public void parseMongodbDataToJson () {}} @ Scheduled invalid troubleshooting record @ Scheduled invalid troubleshooting record

The company before the project to add a regular processing, feel so easy.

@ Componentpublic class CommonSchedule {/ / @ Scheduled (cron = "0 01 * *?") @ Scheduled (cron = "* / 5 *?") Public void avg () {System.out.println ("the current time to start calculating the average is");}}

I thought it was done, but it didn't work!

Start searching for information online.

@ EnableScheduling also added no effect!

@ Lazy (false) is also added without effect!

Began to panic, read the package path is no problem ah, want to use xml to match again

It still doesn't work!

At this time, the front end visited my interface, looked at log, shit system printed!

Calm down for a while.

@ Lazy (false) does not work? It doesn't make sense, and then start to go through the configuration file to see if some bean add default-lazy-init= "true" attribute, and there is no ah.

Finally, it is found that:

I don't know which weird guy wrote off the business.

Decisively uncomment to solve the problem.

Thank you for reading, the above is the content of "@ Scheduled does not implement what to do". After the study of this article, I believe you have a deeper understanding of the problem of @ Scheduled not implementing how to do, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Version problem what to do or file learning configuration no code task company content properties solution yes China plus decisive bad front end Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple Huawei macOS Microsoft