📄 timerservlet.java
字号:
package cn.jx.ecjtu.oa.servlets;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.jx.ecjtu.oa.services.RefreshTask;
import cn.jx.ecjtu.oa.services.TimeSaveTask;
/**
* @todo: 这是一个用来更新维护appliaction中的在线人员列表的 servlet.随web应用启动而启动,直到这个应用退出 (更新appliaction中在线人员列表的在线时间和维护在线人员数量)
* @author yuankai
* @version $Revision: 1.2 $
* @since 1.0
*/
public class TimerServlet extends HttpServlet {
private static final long serialVersionUID = 6283044987900458377L;
private Timer timer=null;
private RefreshTask task =null;
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
//销毁定时器
if(null!=timer)
timer.cancel();
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
ServletContext context=this.getServletContext();
// (true为用定时间刷新缓存)
String start_app_task= getInitParameter("start_task");
// 定时刷新时间(分钟)
long app_delay = Long.parseLong(getInitParameter("delay"));
// 启动定时器 在线列表内存更新
if(start_app_task.equals("true")){
timer = new Timer(true);
task = new RefreshTask(context);
timer.schedule(task, app_delay * 60 * 1000, app_delay * 60 * 1000);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -