@Override public void contextInitialized(ServletContextEvent event) { try { // 初始化配置 ConfigUtil.configure( event.getServletContext().getRealPath("/"), event.getServletContext().getRealPath("/WEB-INF/config/web-config.txt")); // 初始化日志 PropertyConfigurator.configure( event.getServletContext().getRealPath("/WEB-INF/config/log4j.properties")); // 初始化Application Application.configure(event.getServletContext()); // 初始化数据库 HibernateSessionFactory.configure( event.getServletContext().getRealPath("/WEB-INF/config/hibernate.cfg.xml")); // 初始化业务线程池 HttpServletThreadPoolExcutorContainer.configure( event.getServletContext(), "com.flower", new ThreadPoolConfig( ThreadPoolType.TIMER_THREADPOOL.name(), ThreadPoolKindEnum.SCHEDULE, 1, 0, new MyThreadFactory(ThreadPoolType.TIMER_THREADPOOL.name(), "时间线程", 1)), new ThreadPoolConfig( ThreadPoolType.LOGIC_THREADPOOL.name(), ThreadPoolKindEnum.FAIR, 5, 5, new MyThreadFactory(ThreadPoolType.LOGIC_THREADPOOL.name(), "逻辑线程", 5))); } catch (Exception e) { log.error("初始化Servlet容器异常", e); } }
@Override public void contextDestroyed(ServletContextEvent event) { HttpServletThreadPoolExcutorContainer.shutdown(); HibernateSessionFactory.shutdown(); ScheduledExecutorService cleanSessionTimer = (ScheduledExecutorService) event .getServletContext() .getAttribute(ServletContextKeyEnum.USER_DEFINED_SESSION_CLEAN_TIMER); if (cleanSessionTimer != null) cleanSessionTimer.shutdown(); }