Public CheckSevicesDateTaskListener () {
}
Private Timer Timer=null;
Public void contextInitialized (ServletContextEvent sce) {
The timer=new timer (true);
Sce. GetServletContext (). The log (" start the timer ");
//set time
Calendar ca=Calendar.getInstance();
Int year=ca. Get (ca. Year);
Int the month=ca. Get (ca. The month);
Int day=ca. Get (ca. DAY_OF_MONTH);
//the execution of
2 o 'clock in the morning every dayCa. Set (year, month, day, 2, 00, 00);
The Date the Date=ca. GetTime ();
Int period=24 * 60 * 60 * 1000;
The timer. The schedule (new CheckSevicesDateTimerTask (sce) getServletContext ()), the date, period);
Sce. GetServletContext (). The log (" has been added task scheduling table ");
UpdateFileRecordState ();
}
Public void contextDestroyed (ServletContextEvent sce) {
The timer. The cancel ();
Sce. GetServletContext (). The log (" timer destroy ");
}
Public void updateFileRecordState () {
UmDBManager. UpdateFileRecordState (1, 2);
}
}
Ask how to solve the great god, each deployment time will perform a task, rather than the 2 o 'clock to perform again,,,
CodePudding user response:
Int day=ca. Get (ca. DAY_OF_MONTH); -- -- -- -- -- -- -- -- -- -- because this line cause unless you are at 0:00 - it happened to start the service, otherwise it will lead to perform timing as soon as you start the service tasks,Modified into
Int day=ca. Get (ca. DAY_OF_MONTH) + 1; -- -- -- -- -- -- -- -- -- -- to ensure that the next day at 2:00 in the morning to execute
If it is the last day of a month or a year, the last day of their own modification works of information
So start don't perform, until the next day 2 points will perform
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
If you are not at ease, add a judgment for application deployment startup 24 hour under the data, if it is less than 2, is set to int day=ca. Get (ca. DAY_OF_MONTH);
If it is greater than 2 set to int day=ca. Get (ca. DAY_OF_MONTH) + 1;
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Now there are no other people registered timing task by this way, bad management, to study the distributed elastic job