Scheduledthreadexecutor only supports relative time. Interface scheduleatfixedrate prototype definition and parameter description//public scheduledfuture<?> scheduleatfixedrate (Runnable command,long
Initialdelay,long period,timeunit unit); Command: Execute thread initialdelay: Initialization delay period: Two start minimum interval unit: Time units public class ReportListener implements
servletcontextlistener{private Reportservice Reportservice;
Public Reportservice Getreportservice () {return reportservice;
public void Setreportservice (Reportservice reportservice) {this.reportservice = Reportservice; @Override public void contextinitialized (Servletcontextevent sce) {ServletContext ServletContext = Sce.getservlet
Context ();
Webapplicationcontext WAC = Webapplicationcontextutils.getrequiredwebapplicationcontext (ServletContext);
Reportservice = (reportservice) wac.getbean ("Reportservice", Reportservice.class);
Long oneday = 24 * 60 * 60 * 1000; Long Scoredelay=gettimemillis ("09:00:00")-System.currenttimemillis ()/monthly resident points SMS reminder (starting 9 o'clock in the morning 1th/month) Scoredelay = sCoredelay > 0?
Scoredelay:oneday + scoredelay;
TODO Runnable lastmonthscore = new Runnable () {public void run () {Calendar c = calendar.getinstance (); int nowyear = C.get (calendar.year);//Current year int lastmonth = C.get (calendar.month);/Last month int date=c.get (Calendar.DAT
E); If the current date is number 1th, send (==1) if (c.get (calendar.date) = = 1) {for (int i=0;i<comminlist.size (); i++) {String Co
Mminid = string.valueof (Comminlist.get (i). GetId ());
List<userbean> userlist = Reportservice.getuserlistbycomminid (Comminid);
for (int s=0;s<userlist.size (); s++) {//Get user UserBean User=userlist.get (s); Recyclable garbage can be put into integral String recoveryscore=reportservice.getrecoveryscoreforlastmonth (User.getcommid () + "", User.getid ().
ToString ()); Timing fixed-point Placement Integral String otherscore=reportservice.getotherscoreforlastmonth (User.getcommid () + "", User.getid (). ToString ()
); Patrol Integral String inspection=reportservice.getinspectionforLastmonth (User.getcommid () + "", User.getid (). toString ());
Total integral int totalscore=integer.parseint (Recoveryscore) +integer.parseint (Otherscore);
Last month, consumption points String Businessdisprice=reportservice.getbusinessdisprice (User.getcommid () + "", User.getid (). toString ()); SMS Content String logstring= "Respected Users:" +user.getname () + "Hello." "+nowyear+" Year "+lastmonth+" month you get the total points for: "+totalscore+", where the inspection points for: "+inspection+", recyclable garbage put points for: "+recoveryscore+", Timing fixed-point points are: "+otherscore+", you last month to spend points: "+businessdisprice+", the remaining available points for: "+user.getintegral () +".
";
System.out.println (logstring);
Log loggerutil.logforlastmonthscoresms (logstring);
Send SMS Smsserviceutils.sendmobilemsg (User.getmobilephone (), logstring);
}
}
}
}};
Scheduledexecutorservice service = Executors.newsinglethreadscheduledexecutor ();
Service.scheduleatfixedrate (Lastmonthscore, Scoredelay, Oneday, timeunit.milliseconds); }
}