src/org/nutz/runner/NutRunner.java
protected void doIt() {
        while (!lock.isStop()) {
            synchronized (lock) {
                try {
                    // 修改一下本线程的时间
                    upAt = Times.now();
                    downAt = null;
                    if (debug && log.isDebugEnabled())
                        log.debugf("%s [%d] : up", rnm, ++count);

                    // 执行业务
                    interval = exec();

                    if (interval < 1)
                        interval = 1; // 不能间隔0或者负数,会死线程的

                    // 等待一个周期
                    downAt = Times.now();
                    if (debug && log.isDebugEnabled())
                        log.debugf("%s [%d] : wait %ds(%dms)", rnm, count, interval / 1000, interval);
                    lock.wait(interval);
                }
                catch (InterruptedException e) {
                    log.warn(String.format("%s has been interrupted", rnm), e);
                    break;
                }
                catch (Throwable e) {
                    log.warn(String.format("%s has some error", rnm), e);
                    try {
                        lock.wait(sleepAfterError * 1000);
                    }
                    catch (Throwable e1) {
                        log.warn(String.format("%s has some error again", rnm), e);
                        break;
                    }
                }
            }
        }
    }
protected void doIt() {
        while (!lock.isStop()) {
            synchronized (lock) {
                try {
                    // 修改一下本线程的时间
                    upAt = Times.now();
                    downAt = null;
                    if (debug && log.isDebugEnabled())
                        log.debugf("%s [%d] : up", rnm, ++count);

                    // 执行业务
                    interval = exec();

                    if (interval < 1)
                        interval = 1; // 不能间隔0或者负数,会死线程的

                    // 等待一个周期
                    downAt = Times.now();
                    if (debug && log.isDebugEnabled())
                        log.debugf("%s [%d] : wait %ds(%dms)", rnm, count, interval / 1000, interval);
                    lock.wait(interval);
                }
                catch (InterruptedException e) {
                    log.warn(String.format("%s has been interrupted", rnm), e);
                    break;
                }
                catch (Throwable e) {
                    log.warn(String.format("%s has some error", rnm), e);
                    try {
                        lock.wait(sleepAfterError * 1000);
                    }
                    catch (Throwable e1) {
                        log.warn(String.format("%s has some error again", rnm), e);
                        break;
                    }
                }
            }
        }
    }
protected void doIt ( ) { while ( ! lock . isStop ( ) ) { synchronized ( lock ) { try { // 修改一下本线程的时间 upAt = Times . now ( ) ; downAt = null ; if ( debug && log . isDebugEnabled ( ) ) log . debugf ( "%s [%d] : up" , rnm , ++ count ) ; // 执行业务 interval = exec ( ) ; if ( interval < 1 ) interval = 1 ; // 不能间隔0或者负数,会死线程的 // 等待一个周期 downAt = Times . now ( ) ; if ( debug && log . isDebugEnabled ( ) ) log . debugf ( "%s [%d] : wait %ds(%dms)" , rnm , count , interval / 1000 , interval ) ; lock . wait ( interval ) ; } catch ( InterruptedException e ) { log . warn ( String . format ( "%s has been interrupted" , rnm ) , e ) ; break ; } catch ( Throwable e ) { log . warn ( String . format ( "%s has some error" , rnm ) , e ) ; try { lock . wait ( sleepAfterError * 1000 ) ; } catch ( Throwable e1 ) { log . warn ( String . format ( "%s has some error again" , rnm ) , e ) ; break ; } } } } }
做一些需要定期执行的操作
做一些需要定期执行的操作