demand:
A single table time, the new state (initially 0) field, the required time to time, the state of the record will be set to 1
Ideas:
Make additions and changes to the normal, direct deposit these two fields to a database, and then writing in public class monitor, every 2 minutes the database is less than the system time field is set to 1
Code:
Monitor categories:
public class SystemListener implements ServletContextListener {
private Timer timer = null;
public void contextDestroyed(ServletContextEvent arg0) {
if (timer != null) {
timer.cancel();
}
}
public void contextInitialized(ServletContextEvent arg0) {
if (timer == null) {
System.out.println("审核监听开启...");
timer = new Timer();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 90);
calendar.set(Calendar.SECOND, 0);
// service startup performed once a minute, for 2 minutes to perform a
timer.schedule (new new SynJzbmsj (), 1000 * 60, 2 * 1000 * 60);
}
}
}
Modify the status categories:
SynJzbmsj the extends the TimerTask {class public
Private Logger Logger.getLogger = log (SynJzbmsj.class);
@Override
public void RUN () {
the try {
log.info ( "modified state as at the time of registration");
Long time_s = System.currentTimeMillis ( );
SYN ();
Long time_e = System.currentTimeMillis ();
log.info ( "modification status as of the time of application, time-consuming (MS):" + (time_e-time_s));
} the catch (Exception E) {
e.printStackTrace ();
}
}
Private void SYN () {
the try {
// modification degree programs off state registration time
String SQL = "Update WEB_XWXM SET sjzt = '0' WHERE JZBMSJ <= SYSDATE";
DBManagerUtil new new DBManagerUtil DB = () ;
db.Execute (SQL);
} the catch (Exception E) {
log.error (+ e.toString (), E "modifying the state of an error as at the registration time");
e.printStackTrace ();
}
}
}
web.xml file to configure the Listener
<listener>
<listener-class>
yansoft.common.SystemListener
</listener-class>
</listener>
Since you're done!