Monday, November 30, 2015

Timer 计时器

private void getAgentLocalInfo(){
    if(curTimer == null){
        curTimer = new Timer(true);    }

    curTimer.schedule(new java.util.TimerTask() {
        @Override        public void run() {
            startLocalInfo();        }
    }, 5000, 6 * 1000);}

/**
 * Schedule a task for repeated fixed-delay execution after a specific delay.
 *
 * @param task
 *            the task to schedule.
 * @param delay
 *            amount of time in milliseconds before first execution.
 * @param period
 *            amount of time in milliseconds between subsequent executions.
 * @throws IllegalArgumentException
 *                if {@code delay < 0} or {@code period <= 0}.
 * @throws IllegalStateException
 *                if the {@code Timer} has been canceled, or if the task has been
 *                scheduled or canceled.
 */
public void schedule(TimerTask task, long delay, long period) {
    if (delay < 0 || period <= 0) {
        throw new IllegalArgumentException();
    }
    scheduleImpl(task, delay, period, false);
}



refence:
http://blog.csdn.net/mariofei/article/details/11686855

No comments:

Post a Comment