It is quite simple to use the built-in jdk TimerTask for simple task processing;
When spring cannot be injected, the specific performance is as follows:
@ Resource annotation is not supported on static fields
1. The corresponding dao can be injected at the first startup.
2. When the run method is executed in the middle, dao is NULL.
The solution is to introduce a static initialization to convert:
@ Resource
Private BookDao bookDao;
Private static BookDao bkDao;
Public void start (){
BkDao = this. bookDao;
If (! Start ){
VisitStatServiceUtil daemon = new VisitStatServiceUtil ();
Click_timer = new Timer ("VisitStatServiceUtil", true );
Click_timer.schedule (daemon, INTERVAL, INTERVAL); // The INTERVAL between running and running is 1 minute.
Start = true;
}
Log.info ("VisitStatService started .");
}
Note: You can use get set to enable xml configuration to take effect. (a series of problems caused by removing the DAO and Service xml configuration files from the project are broken one by one to switch to the annotation mode)