赞
踩
package com.esafenet.ta.da.reoortriskrule.listener; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class ReportRiskRule implements ServletContextListener{ private ReportThread reportThread = null; /** * 上下文销毁时监听执行方法 */ @Override public void contextDestroyed(ServletContextEvent arg0) { System.out.println("哎呦 关了"); destroyThread(); } /** * 上下文启动时监听执行方法 */ @Override public void contextInitialized(ServletContextEvent arg0) { System.out.println("哎呦启动了"); startThreat(); } /** * 启动线程 */ private void startThreat() { if(reportThread==null){ reportThread = new ReportThread(); reportThread.start(); } } /** * 销毁线程 */ private void destroyThread() { if(reportThread != null && reportThread.isInterrupted()){ reportThread.interrupt(); } } /** * 轮训的线程执行下级给上级上报风险数据 * @author Administrator * */ private class ReportThread extends Thread{ @Override public void run() { while(true){ try { System.out.println("我是轮训一直输出"); Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } // public static void main(String[] args) { // if(reportThread==null){ // reportThread = new ReportThread(); // reportThread.start(); // } // } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。