84bbf3658fa01fd01a67c10ecbc38d7d2b551b3d.svn-base
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.bjivt.job.robot.listener;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.bjivt.job.robot.handler.LiveJobHandler;
import com.bjivt.job.robot.handler.LiveOfflineHandler;
import com.bjivt.job.robot.service.IRobotDataService;
/**
*
* WebServletContextListener
*
* yihong.tan@woaner.cn 2014年11月3日 下午3:04:51
*
* @version 1.0.0
*
*/
public class WebServletContextListener implements ServletContextListener {
private static transient Logger logger = LoggerFactory.getLogger(WebServletContextListener.class);
// private final long theNextTime = 1000 * 30 ;
private static ApplicationContext ctx = null;
/**
* 创建一个新的实例 WebServletContextListener.
*
*/
public WebServletContextListener() {
}
/*
* (non-Javadoc)
*
* @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.
* ServletContextEvent)
*/
@Override
public void contextDestroyed(ServletContextEvent arg0) {
}
/*
* (non-Javadoc)
*
* @see
* javax.servlet.ServletContextListener#contextInitialized(javax.servlet.
* ServletContextEvent)
*/
@Override
public void contextInitialized(ServletContextEvent sce) {
logger.debug("服务器启动");
ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
IRobotDataService robotDataService = (IRobotDataService)ctx.getBean("robotDataService");
System.out.println("========服务器启动======");
ScheduledExecutorService service = Executors.newScheduledThreadPool(2);
LiveJobHandler ljh = new LiveJobHandler();
ljh.setRobotDataService(robotDataService);
service.scheduleAtFixedRate(ljh, 5, 2l, TimeUnit.SECONDS);
// LiveOfflineHandler loh = new LiveOfflineHandler();
// loh.setRobotDataService(robotDataService);
// service.scheduleAtFixedRate(loh, 5, 2l, TimeUnit.SECONDS);
}
}