Originally to do the purpose of data mining in which network, the structure has become a system development.
。
Just still more serious to do for three months, the teacher very much agree with my work attitude and results.
。
The internship will be over soon. Summarize some of the things that have not been noticed before and become habits and problems and share them with you.
At the same time to make an advertisement: to which network Internal audit department recruit Javaweb Development intern. Time is free, one day a week, Saturday Sunday, even. The time of the small partners to give me a message ah, earn an allowance, but also a long experience.
。。 (GPA, a senior dog who wants to work is the most suitable.)
。。 )
In fact, timed tasks are very easy. JS has actually done it. is the Timer class Timer.schedule (timertask task, Date time, long period) method , the three parameters are: task, delay, interval.
Give a complete code:
The first is the Bugxmltimer class:
public class Bugxmltimer {public Timer timer;public void Timerstart () {timer = new timer ();D ate datetime=new Date ();D A Te midnightdate=new Date (); SimpleDateFormat sdf1 = new SimpleDateFormat ("Yyyy-mm-dd"); SimpleDateFormat sdf2 = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); try { midnightdate = Sdf2.parse (Sdf1.format (datetime) + "10:06:00"), } catch (ParseException e) { //TODO Auto-generated Catch block e.printstacktrace (); } SYSTEM.OUT.PRINTLN ("before task"); Long time = Midnightdate.gettime ()-datetime.gettime (); Run immediately, then run once every 10s timer.schedule (New Bugxmltimertask (), 0, 10000);//time} public void Timerstop () {if ( Timer!=null) Timer.cancel ();} public static void Main (string[] args) {Bugxmltimer mytimer=new bugxmltimer (); TODO auto-generated Method Stub Mytimer.timerstart ();} }
Next is the TimerTask class:
<pre name= "code" class= "Java" >public class Bugxmltimertask extends TimerTask { @Override public void Run ( { System.out.print ("Run Task"); try {<strong>sendmail ();//The next blog teaches you to send mail </strong>} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();}}}
Finally, add the Listener class:
public class Mytimerlistener implements Servletcontextlistener {<span style= "White-space:pre" ></span> Private Bugxmltimer MyTimer = new Bugxmltimer (); public void contextinitialized (Servletcontextevent event) { mytimer.timerstart (); } public void contextdestroyed (Servletcontextevent event) { mytimer.timerstop (); } }
Finally, don't forget to configure the Listener node for Web. xml:
<listener> <listener-class>com. Timelistener.mytimerlistener</listener-class></listener>
Where to go net internship summary: Development of timed tasks (Javaweb)