JAVA WEB程序中添加定时器
//这是我的定时器类,用来定时执行某段任务;
package com.my.time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
public
class
BugXmlTimer {
public
Timer timer;
public
void
timerStart(){
timer =
new
Timer();
Date datetime=
new
Date();
Date midnightDate=
new
Date();
SimpleDateFormat sdf1 =
new
SimpleDateFormat(
"yyyy-MM-dd"
);
SimpleDateFormat sdf2 =
new
SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss"
);
try
{
midnightDate = sdf2.parse(sdf1.format(datetime)+
" 23:00:00"
);
}
catch
(ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long
in
=midnightDate.getTime()-datetime.getTime();
System.
out
.println(
"before task"
);
//立刻执行,然后每隔30s执行一次
timer.schedule(
new
BugXmlTimerTas
相关文档:
Java学习从入门到精通
一、 JDK (Java Development Kit)
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......
淘宝用开源,微软用自己的东西,金山什么都用,Google、IBM和ORACLE以及JBOSS则全力支持OpenSource,诸多公司,我也不细评
了,从最终产品运行效率看,微软最差,Windows
Live系列的产品慢的不成样(最近几个月才略有改观),反倒是用开源的一个比一个快;看看google和淘宝。所以说,没有什么快慢,只 ......
java exception 解决方案 - 我的异常网|异常|exception|myexception 831 - ActionMessages 832 - could not instantiate id generator 833 - javax.servlet.jsp.JspException 834 - javax.naming.NoInitialContextException 835 - net.sf.hibernate.HibernateException 836 - org.hibernate.exception.GenericJDBCExceptio ......