当前位置: 代码迷 >> Web前端 >> WEB 中起动线程
  详细解决方案

WEB 中起动线程

热度:103   发布时间:2012-10-27 10:42:26.0
WEB 中启动线程
public class SystemContextListener implements ServletContextListener { 
 
    private MyThread thread = null; 
    @Override 
    public void contextDestroyed(ServletContextEvent arg0) { 

        thread.setAppIsAlive(false); 
    } 
 
    @Override 
    public void contextInitialized(ServletContextEvent e) { 
        ServletContext ctx = e.getServletContext(); 
        ctx.setAttribute("onlineUser", new ConcurrentHashMap<String, Date>()); 
        MyThread myThread = (MyThread ) 
                WebApplicationContextUtils.getWebApplicationContext(ctx).getBean("MyThread "); 
        onlineUserCheckThread.setName("MyThread "); 
        thread = checkThread; 
        thread.start(); 
         
    } 
 
 
  相关解决方案