📄 dbtimerefreshservlet.java
字号:
package cn.jx.ecjtu.oa.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Timer;
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;
public class DBTimeRefreshServlet extends HttpServlet {
private Timer db_timer=null;
private TimeSaveTask db_task =null;
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
//销毁定时器
if(null!=db_timer)
db_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 occure
*/
public void init() throws ServletException {
ServletContext context=this.getServletContext();
// (true为用定时间刷新缓存)
String start_db_task= getInitParameter("start_task");
// 定时刷新时间(分钟)
long db_delay = Long.parseLong(getInitParameter("delay"));
// 启动定时器 在线列表数据库更新
if(start_db_task.equals("true")){
db_timer = new Timer(true);
db_task = new TimeSaveTask(context);
db_timer.schedule(db_task, db_delay * 60 * 1000, db_delay * 60 * 1000);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -