java定时器
web.xml
<servlet>
<servlet-name>CallBackServlet</servlet-name>
<servlet-class>com.icss.fsop.osems.workspace.servlet.CallBackServlet</servlet-class>
<load-on-startup>156</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CallBackServlet</servlet-name>
<url-pattern>/servlet/CallBackServlet</url-pattern>
</servlet-mapping>
public class CallBackTask extends TimerTask{
/**
* 执行时间控制器
*/
public void run() {
// TODO Auto-generated method stub
StringBuffer sql = new StringBuffer();
sql.append(" update tbl_os_item tblItem ")
.append(" set tblItem.ITEMSPACE = 'issued' ")
.append(" where sysdate - to_date(tblItem.pi_sign_time, 'yyyy-MM-dd hh24:mi:ss') >= 7 ")
.append(" and tblItem.State = '2' ")
.append(" and tblItem.proid in ")
.append(" (select proid from tbl_os_project where protype != '0') ")
.append(" and tblItem.ITEMSPACE = 'workspace' ");
String sqlStr = sql.toString();
Connection conn = null;
PreparedStatement ps = null;
try {
conn=DBConnectionProvider.getConnection(Constants.JNDI_OSEMS);
ps = conn.prepareStatement(sqlStr);
ps.execute();
//conn.commit();
ps.close();
} catch (Exception e) {
// TODO: handle exception
}finally {
try {
conn.close();
} catch (Exception e) {
// TODO: handle exception
}
}
}
}
/**
*
*/
package com.icss.fsop.osems.workspace.servlet;
import java.util.Timer;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import com.icss.core.config.Config;
import com.icss.core.config.ConfigException;
import com.icss.core.config.ConfigType;
import com.icss.fsop.osems.common.conf.Constants;
import com.icss.fsop.osems.common.util.CallBackTask;
public class CallBackServlet extends HttpServlet {
Timer time = new Timer();
CallBackTask task = new CallBackTask();
public void init(ServletConfig config) {
try
{
Config.addConfig(ConfigType.PROP, Constants.APP_CONFIG,"osems_env.properties");
int initTime = Integer.parseInt(Config.getConfig(Constants.APP_CONFIG).getProperty("initTime", "")) ;
int intervalTime = Integer.parseInt(Config.getConfig(Constants.APP_CONFIG).getProperty("intervalTime", "")) ;
time.schedule(task, initTime, intervalTime);
} catch (ConfigException e)
{
//do something
e.printStackTrace();
}
}
public void destroy() {
time.cancel();
}
}
osems_env.properties
intervalTime = 3600000
initTime = 120000