美文网首页
Timer定时器的使用

Timer定时器的使用

作者: 阿__飞 | 来源:发表于2018-05-29 14:06 被阅读0次

    1.java项目中使用定时器来完成定时任务 

    public void getEmpById() throws IOException {

    // 创建 Timer 对象

    Timer timer = new Timer(true);

    // 调用定时方法

    timer.schedule(new java.util.TimerTask() {public void run(){

    try {

    // 调用需要定时执行的方法

    checkNewMail();

    } catch (IOException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    }

    // 参数0,代表延迟执行的时间

    // 参数 2 * 60 * 1000 代表每2分钟执行一次

    }, 0, 2 * 60 * 1000);

    }

    相关文章

      网友评论

          本文标题:Timer定时器的使用

          本文链接:https://www.haomeiwen.com/subject/yeeyxftx.html