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();
}
}