scheduledexecutorservice-the specified tasks on a timed cycle

Source: Internet
Author: User
Tags prototype definition

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); }
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.