void checkUserClockChange() { if (!hasUserClockTasks()) { return; } final long userClockSkew = Timer.userClockSkew(); if (userClockSkew == 0) { return; } if (userClockSkew < 0) { for (int i = 1; i <= size; i++) { TimerTask task = queue[i]; if (task != null && task.isUserClock) { task.nextExecutionTime -= userClockSkew; fixUp(i); } } } else { for (int i = size; i >= 1; i--) { TimerTask task = queue[i]; if (task != null && task.isUserClock) { task.nextExecutionTime -= userClockSkew; fixDown(i); } } } }
/** * Adds a new task to the priority queue. * * @param task to add to the current queue */ void add(TimerTask task) { // Grow backing store if necessary if (++size == queue.length) { TimerTask[] newQueue = new TimerTask[2 * queue.length]; System.arraycopy(queue, 0, newQueue, 0, size); queue = newQueue; } queue[size] = task; fixUp(size); if (task.isUserClock) { userClockTaskAdded(); } }