The majority of Java Web requests are made using the Configure listener implementation in XML!
Here I wrote a timer can also meet the same requirements! And you can control the start or shut down, and can be set within 1 days to execute the timer at 6,9,12 Point, feeling
Listen to the flexible!
What kind?
The background code is as follows:
/** * * * * * @author Qiyulin * * * */@Controller () @Scope ("prototype") public class MapAction extends genericaction{ Private static final Long Serialversionuid = -8570260939683969514l;private static MyTimer mt;//Timer Data synchronization private String msg; Public String Timer () {String on = Request (). GetParameter ("on"); String times = Request (). GetParameter ("Times"), if (times) times = "1", if (!empty (ON) && "yes". Equals (ON)) {//Start timer MT =new MyTimer (times); Mt.start (new Mytimercallback () {public void finshed (int status) {switch (status) {Case 1: SYSTEM.ERR.PRINTLN ("Timer: triggered"); Break;case 0:system.err.println ("Timer: not triggered"); break;}}); Msg= "Timer has been started";} else if (!empty (ON) && "No", Equals (ON)) {//Turn off Timer if (mt!=null) {mt.end (new Mytimercallback () {public void finshed ( int status) {//do somethingSystem.out.println ("timer: Closed");}}); Msg= "timer has been closed";} Else{msg= "Welcome to Timer";} return appconstants.return_type_freemarker;} Null to determine Private Boolean empty (Object obj) {if (null!=obj&&! "". Equals (obj)) {return false;} Return true;} Inner class Mytimer{private string hours;private timer timer = new Timer (true);p ublic MyTimer (string hours) {this.hours = h Ours;} public void Start (final Mytimercallback callback) {Timer.schedule (new TimerTask () {@SuppressWarnings ("deprecation") @ overridepublic void Run () {Calendar cal = Calendar.getinstance (); String hs[] = Hours.split (","); int hour= cal.gettime (). GetHours (); Boolean b=arrays.aslist (HS). Contains (string.valueof (hour)); if (b) {callback.finshed (1);} else{callback.finshed (0);}}, 0,10*1000);} public void End (Mytimercallback callback) {timer.cancel (); callback.finshed (2);}} Callback Interface mytimercallback{void finshed (int status);} Public String getmsg () {return msg;} public void Setmsg (String msg) {this.msg = msg;}}
The page code is as follows:
Feel very good, haha, work ....Original: Http://blog.csdn.net/qilin001cs
JAVA Web implementation can control timers