WebContextServlet.java
2.74 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* @Title: WebContextServlet.java
* @Package com.bjivt.job.robot.listener
* @Description: TODO(用一句话描述该文件做什么)
* @author Yh.T
* @date 2016年8月3日 下午3:53:07
* @version
*/
package com.bjivt.web.interceptor;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.bjivt.entity.showtime.SystemNotice;
import com.bjivt.service.showtime.SystemNoticeService;
import com.bjivt.service.showtime.UserService;
import com.bjivt.web.thread.SystemNoticeThread;
import com.bjivt.web.thread.ThreadPool;
/**
* 项目名称:robot
*
* 类描述:
* 类名称:com.bjivt.job.robot.listener.WebContextServlet
* Yh.T
* 创建时间:2016年8月3日 下午3:53:07
* 修改备注:
* @version
*/
public class WebContextServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
@Override
protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
// TODO Auto-generated method stub
super.service(arg0, arg1);
}
@Override
public void init() throws ServletException {
// TODO Auto-generated method stub
super.init();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
SystemNoticeService systemNoticeService = (SystemNoticeService)ctx.getBean("systemNoticeService");
UserService userService = (UserService)ctx.getBean("userService");
System.out.println("==================服务器启动=====================");
//是按循环的才调用
List<SystemNotice> noticeList = systemNoticeService.getNoticeAsAction(2);
ThreadPool pool = ThreadPool.getInstance();
for(SystemNotice notice:noticeList){
ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
SystemNoticeThread snt = new SystemNoticeThread();
snt.setType(notice.getType());
snt.setUserService(userService);
snt.setNotice(notice);
pool.putNotice(notice.getId(), snt);
service.scheduleAtFixedRate(snt, 5, notice.getIntervalTime(), TimeUnit.MINUTES);
}
}
@Override
public void destroy() {
// TODO Auto-generated method stub
super.destroy();
}
}