Technical Analysis of Membership Card Management System (18) timed monitoring of Timer and membership card timer
Technical Analysis of the membership card management system (18) Timer monitoring of Timer in web applications. Sometimes the customer needs some Timer programs and does not need to operate them on their own, but is triggered by the application itself (proxy) perform some operations. At this time, the monitoring and timer can be used together to basically achieve this requirement. A lot of code on the internet is incomplete, the level is not yet reached, it seems too difficult. The following is the maximum number of documents maintained by the system at 00:00:00 every day for instance parsing. First, establish relevant Bahe classes, such:
Figure 1
Then, register the timer and listener class in "web. xml". The Code is as follows:
<servlet> <servlet-name>listener</servlet-name> <servlet-class>MEMBCERP.Servlet.servletlistener</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>listener</servlet-name> <url-pattern>/listener.do</url-pattern> </servlet-mapping>
Then, the scheduled listening is compiled. The Code is as follows:
Package MEMBCERP. servlet; import java. util. timer; import javax. servlet. servletConfig; import javax. servlet. servletException; import javax. servlet. http. httpServlet; public class servletlistener extends HttpServlet {/* listens to system proxy events */private Timer timer = null; public void init (ServletConfig config) throws ServletException {super. init (config); timer = new Timer (true); timer. schedule (new Todo (), 0, 1000);/* parameter: Method redirection, delay, execution interval */}}
Finally, the system is monitored to conform to the program, and the system is maintained if the conditions are met. The Code is as follows:
Package MEMBCERP. servlet; import java. text. simpleDateFormat; import java. util. date; import java. util. timerTask; import MEMBCERP. IService. jianKaYuFaFangIService; import MEMBCERP. service. jianKaYuFaFangService; import MEMBCERP. pojo. sysMaxNumber; public class Todo extends TimerTask {@ Override public void run () {SimpleDateFormat df = new SimpleDateFormat ("HH: mm: ss "); // set the date format String timDate = df. format (new Date (); // whether the listener Performs routine maintenance if (timDate. equals ("00:00:00") {ChuShiHuaZuiDaDanJuShu () ;}} public login jianKaYuFaFangService = new JianKaYuFaFangService (); // instantiate the class // The maximum number of documents on the day of initialization public void authentication () {SysMaxNumber lstZuiDaDanJuShu = new SysMaxNumber (); lstZuiDaDanJuShu. setDiaoBoJiLuZuiDaShu (0); lstZuiDaDanJuShu. setFaFangJiLuZuiDaShu (0); lstZuiDaDanJuShu. setGuaShiHuiFuJiLuZuiDaShu (0); lstZuiDaDanJuShu. setHuiYuanKaZuoFeiJiLuZuiDaShu (0); lstZuiDaDanJuShu. setHuiYuanKaHuanKaJiLuZuiDaShu (0); lstZuiDaDanJuShu. setHuiYuanKaYouXiaoQiGengGaiJiLuZuiDaShu (0); lstZuiDaDanJuShu. setHuiYuanKaZhuangTaiBianDongJiLuZuiDaShu (0); lstZuiDaDanJuShu. setId (0); lstZuiDaDanJuShu. setKuCunKaYouXiaoQiBianGengJiLuZuiDaShu (0); lstZuiDaDanJuShu. setKuCunKaZuoFeiJiLuZuiDaShu (0); lstZuiDaDanJuShu. setLingKaJiLuZuiDaShu (0); lstZuiDaDanJuShu. setTuiLingJiLuZuiDaShu (0); lstZuiDaDanJuShu. setGuaShiJiLuZuiDaShu (0); lstZuiDaDanJuShu. setJianKaJiLuZuiDaShu (0); lstZuiDaDanJuShu. setKuCunKaZuoFeiHuiFuJiLuZuiDaShu (0); this. jianKaYuFaFangService. updateZuiDaDanJuShu (lstZuiDaDanJuShu );}}
At this point, the membership card management system technical analysis (18) Timer timed listening resolution is completed. If you do not understand, leave a message to ask a question. Note: it is only for learning and cannot be used for commercial purposes! Otherwise, you are solely responsible for the consequences.
@ The final resolution permission is owned by me