//...................................
new Thread {
//线程侦测
public void run() {
while(true) {
//这里扫描你的邮箱
//这里发送
try {
Thread.sleep(60000);//一分钟检查一次
}catch(Exception e) { }
}
}
}.start();
.............................................
new Thread {
//线程侦测
public void run() {
while(true) {
//这里扫描你的邮箱
//这里发送
try {
Thread.sleep(60000);//一分钟检查一次
}catch(Exception e) { }
}
}
}.start();
.............................................
的对象,调用其scheduleAtFixedRate()方法实现定时执行.
大概的例子是这样的:
public class TimerTaskTest00 {
public static void main(String[] args) {
TimerTask task = new TimerTask() {
public void run(){
//你的执行代码.
}
};
Timer timer = new Timer();
timer.scheduleAtFixedRate(task,0,60000);
}
}
public class SendThread extends Thread{
public static final int INTERVAL=3;
public int minute=SendThread.INTERVAL;
public SendThread(){
}
public void run(){
while(true){
if(this.minute==0)
{
System.out.print("sending ....");
System.out.print("complete\n");
this.minute=SendThread.INTERVAL;
}
else{
this.minute--;
}
try{
Thread.sleep(6000);
}catch(Exception e){
e.printStackTrace();
}
}
}
public static void main(String args[]){
Thread t=new SendThread();
t.start();
}
}