cmsschedulerunit.java
来自「cwbbs 云网论坛源码」· Java 代码 · 共 86 行
JAVA
86 行
package cn.js.fan.module.cms;import cn.js.fan.kernel.BaseSchedulerUnit;import cn.js.fan.db.Conn;import cn.js.fan.web.Global;import java.sql.ResultSet;import java.sql.SQLException;import org.apache.log4j.Logger;import java.util.Date;import java.sql.PreparedStatement;import cn.js.fan.util.DateUtil;import cn.js.fan.util.StrUtil;public class CMSSchedulerUnit extends BaseSchedulerUnit { static Logger logger = Logger.getLogger(CMSSchedulerUnit.class.getName()); public static long lastClearTmpAttachmentTime = System.currentTimeMillis(); public static long clearTmpAttachmentInterval = 4 * 60 * 60 * 1000; static { initParam(); } public CMSSchedulerUnit() { lastTime = System.currentTimeMillis(); interval = 600000; name = "CMS Scheduler"; } public static void initParam() { } public void OnTimer(long curTime) { try { if (curTime - lastClearTmpAttachmentTime >= clearTmpAttachmentInterval) { clearTmpAttachment(); lastClearTmpAttachmentTime = curTime; } } catch (Throwable e) { logger.error("OnTimer:" + StrUtil.trace(e)); } } public void clearTmpAttachment() { java.util.Date today = new Date(); Date d2 = DateUtil.addDate(today, -2); Date d10 = DateUtil.addDate(today, -10); String sql = "select id from document_attach where doc_id=-1 and upload_date>? and upload_date<?"; Conn conn = new Conn(Global.defaultDB); ResultSet rs = null; try { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, "" + d10.getTime()); ps.setString(2, "" + d2.getTime()); rs = conn.executePreQuery(); while (rs.next()) { int id = rs.getInt(1); logger.info("clearTmpAttachment: Delete temp attchment id=" + id); Attachment att = new Attachment(id); att.delTmpAttach(); } } catch (SQLException e) { logger.error("clearTmpAttachment:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?