JAVA中定時自動完成任務的實現要用到JAVA中的定時器TimerTask和監聽器
下面的列子很詳細
package com
public class UploadFile{
/**
*實現上傳的代碼s省略 可以看下我下面的
__haiming/blog/static/
__haiming/blog/static/
*/
public void upload()
{
System
}
}
package com
import java
import java
import javax
public class MyTaker extends TimerTask {
private static boolean isRun = false;
private ServletContext context ;
private Calendar ca = Calendar
public MyTaker(ServletContext context)
{
ntext = context;
}
@Override
public void run() {
if(!isRun){
if(
isRun = true;
context
UploadFile uf= new UploadFile();
uf
isRun =false;
context
}
}
else
{
System
}
}
}
package com
import javax
import javax
import com
import java
public class ContexListener implements ServletContextListener{
private Timer timer = null;
@Override
public void contextDestroyed(ServletContextEvent event) {
timer
event
}
@Override
public void contextInitialized(ServletContextEvent event) {
timer = new Timer(true);
event
timer
event
}
}
<!
<listener>
<listener
</listener>
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26450.html