希望对你有启发:
 
  使用这几行代码之后,Timer本身会每隔5分钟调用一遍server.checkNewMail()方法,不需要自己启动线程。Timer本身也是多线程同步的,多个线程可以共用一个Timer,不需要外部的同步代码,
在《The JavaTutorial》中有更完整的例子public class AnnoyingBeep {
    Toolkit toolkit;
    Timer timer;
    public AnnoyingBeep() {
         toolkit = Toolkit.getDefaultToolkit();
        timer = new Timer();
        timer.schedule(new RemindTask(),
                        0,        //initial delay
                        1*1000);  //subsequent rate
    }
    class RemindTask extends TimerTask {
         int numWarningBeeps = 3;
        public void run() {
             if (numWarningBeeps > 0) {
                 toolkit.beep();
                  System.out.println("Beep!");
                  numWarningBeeps--;
             } else {
                 toolkit.beep(); 
                System.out.println("Time's up!");
                 //timer.cancel(); //Not necessary because we call System.exit
                 System.exit(0);   //Stops the AWT thread (and everything else)
             }
        }
    }
    ...}

解决方案 »

  1.   

    希望对你有启发:  使用这几行代码之后,Timer本身会每隔5分钟调用一遍server.checkNewMail()方法,不需要自己启动线程。Timer本身也是多线程同步的,多个线程可以共用一个Timer,不需要外部的同步代码
    在《The JavaTutorial》中有更完整的例子public class AnnoyingBeep {
        Toolkit toolkit;
        Timer timer;
        public AnnoyingBeep() {
             toolkit = Toolkit.getDefaultToolkit();
            timer = new Timer();
            timer.schedule(new RemindTask(),
                            0,        //initial delay
                            1*1000);  //subsequent rate
        }
        class RemindTask extends TimerTask {
             int numWarningBeeps = 3;
            public void run() {
                 if (numWarningBeeps > 0) {
                     toolkit.beep();
                      System.out.println("Beep!");
                      numWarningBeeps--;
                 } else {
                     toolkit.beep(); 
                    System.out.println("Time's up!");
                     //timer.cancel(); //Not necessary because we call System.exit
                     System.exit(0);   //Stops the AWT thread (and everything else)
                 }
            }
        }
        ...}
      

  2.   

    windows
    什么本地代码?有现成的控制传真机的程序吗?
      

  3.   

    可以用RFax 1.0  实现 http://www.java4less.com/java_fax.htm#download