cn.myapps.base.web.listener.StartupListener类学习

cn.myapps.base.web.listener.StartupListener是一个系统启动监听类,

 

让我们一起来看看它到底做了哪些事情:

public class StartupListener extends HttpServlet implements ServletContextListener { // Notification that the web application is ready to process requests /** * */ private static final long serialVersionUID = 1L; private TaskProcess getTaskProcess() throws ClassNotFoundException { return (TaskProcess) ProcessFactory.createProcess(TaskProcess.class); } public void contextInitialized(ServletContextEvent sce) { try { // 关闭性能监控 MonitorFactory.disable(); // 初始化用户以及资源URL try { PersistenceUtils.beginTransaction(); InitSystem.init(); PersistenceUtils.commitTransaction(); } catch (Exception e) { PersistenceUtils.rollbackTransaction(); e.printStackTrace(); } // 初始化应用真实路径 Environment evt = Environment.getInstance(); evt.setApplicationRealPath(sce.getServletContext().getRealPath("/")); // 已废弃 sce.getServletContext().setAttribute(Environment.class.getName(), evt); // 获取myApps的版本,初始化版本号 String hostName = InetAddress.getLocalHost().getHostName(); LicenseUtil.setAppVersion(sce.getServletContext().getRealPath("/"), hostName); // 获取所有任务 Collection taskList = getTaskProcess().doSimpleQuery(null); for (Iterator iter = taskList.iterator(); iter.hasNext();) { Task task = (Task) iter.next(); if (!(task.getStartupType() == TaskConstants.STARTUP_TYPE_AUTO)) { continue; } long delay = 60 * 1000; TimerRunner.registerJSService(task.getApplicationid()); // 根据任务内容新建任务 TimeRunnerAble job = TimerRunner.createTimeRunnerAble(task, getTaskProcess()); // 把运行的任务放进runningList map中 TimerRunner.runningList.put(task, job); TimerRunner.registerTimerTask(job, new Date(), delay); } // 流程催办提醒任务, 30分钟运行一次 Schedule.registerJob(new NotificationJob(), NotificationConstant.JOB_PEIROD, NotificationConstant.JOB_PEIROD); // 流程自动节点任务初始化 AutoAuditJobManager.initJobs(); // 搜索测试 // new SearchFiles().doSearchByField("title", "bar"); // new SearchFiles().doSearchByField("title", "foo"); // 启动索引创建 // IndexBuilder.start(); // 获取WebWork配置 // Map configs = ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfigs(); // for (Iterator iterator = configs.entrySet().iterator(); iterator.hasNext();) { // Entry entry = (Entry) iterator.next(); // System.out.println("key: " + entry.getKey() + " value: " + entry.getValue()); // } } catch (Exception e) { e.printStackTrace(); } finally { try { PersistenceUtils.closeSessionAndConnection(); } catch (Exception e) { e.printStackTrace(); } } } public void contextDestroyed(ServletContextEvent sce) { } }

从以上代码以及注释可以看出:

1)初始化用户以及资源URL

2)初始化应用真实路径

3)获取所有任务

4)流程催办提醒任务, 30分钟运行一次

5)流程自动节点任务初始化

你可能感兴趣的:(exception,Webwork,application,iterator,任务,delay)