//...................................
new Thread {
  //线程侦测
  public void run() {
    while(true) {
      //这里扫描你的邮箱
      //这里发送
      try {
        Thread.sleep(60000);//一分钟检查一次
      }catch(Exception e) { }
    }
  }
}.start();
.............................................

解决方案 »

  1.   

    可以用java.util.TimerTask类生成一个可执行的定时任务,然后实例化一个java.util.Timer
    的对象,调用其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);
    }
    }
      

  2.   

    这是我的代码,因为定时查询,所以没有datetime,直接使用了整数,发送邮件的代码为了简单没有写
    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();
    }
    }