Refine search
/** * Triggers the update with 5 seconds quiet period, to avoid triggering data check too often * when multiple agents become online at about the same time. */ @Override public void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException { synchronized(this) { future.cancel(false); future = Timer.get().schedule(MONITOR_UPDATER, 5, TimeUnit.SECONDS); } } }
private void _cleanUpShutdownTimer(List<Throwable> errors) { LOGGER.log(Level.FINE, "Shutting down timer"); try { Timer.shutdown(); } catch (SecurityException e) { LOGGER.log(WARNING, "Not permitted to shut down Timer", e); errors.add(e); } catch (OutOfMemoryError e) { // we should just propagate this, no point trying to log throw e; } catch (LinkageError e) { LOGGER.log(SEVERE, "Failed to shut down Timer", e); // safe to ignore and continue for this one } catch (Throwable e) { LOGGER.log(SEVERE, "Failed to shut down Timer", e); // save for later errors.add(e); } }
private void schedule(long interval) { Timer.get() .scheduleAtFixedRate(new SafeTimerTask() { public void doRun() { triggerUpdate(); } }, interval, interval, TimeUnit.MILLISECONDS); }
private void periodic() { long interval = 5000; Timer.get().scheduleWithFixedDelay(this, interval, interval, TimeUnit.MILLISECONDS); }
@Override public void stop(Throwable cause) throws Exception { // JENKINS-37154: we might be inside the VM thread, so do not do anything which might block on the VM thread Timer.get().submit(new Runnable() { @Override public void run() { ACL.impersonate(ACL.SYSTEM, new Runnable() { @Override public void run() { doAbort(); } }); } }); }
/** * May be overridden to provide an alternate executor service. * @return by default, {@link Timer#get} */ protected ExecutorService executorService() { return Timer.get(); }
private static void schedulePeriodicWork(PeriodicWork p) { Timer.get().scheduleAtFixedRate(p, p.getInitialDelay(), p.getRecurrencePeriod(), TimeUnit.MILLISECONDS); }
private void periodic() { long interval = 5000; Timer.get().scheduleWithFixedDelay(this, interval, interval, TimeUnit.MILLISECONDS); }
@Override public void interrupt(boolean forShutdown) { if (forShutdown) { return; } LOGGER.log(FINE, "interrupted {0}", cookie); // TODO save the BodyExecution somehow and call .cancel() here; currently we just interrupt the build as a whole: Timer.get().submit(new Runnable() { // JENKINS-46738 @Override public void run() { Executor masterExecutor = r.getExecutor(); if (masterExecutor != null) { masterExecutor.interrupt(); } else { // anomalous state; perhaps build already aborted but this was left behind; let user manually cancel executor slot Executor thisExecutor = /* AsynchronousExecution. */getExecutor(); if (thisExecutor != null) { thisExecutor.recordCauseOfInterruption(r, listener); } completed(null); } } }); } @Override public boolean blocksRestart() {
/** * May be overridden to provide an alternate executor service. * @return by default, {@link Timer#get} */ protected ExecutorService executorService() { return Timer.get(); }
/** * Schedules the next execution. */ public void schedule() { // randomize the scheduling so that multiple Hudson instances will write at the file at different time long MINUTE = 1000*60; Timer.get() .schedule(new SafeTimerTask() { protected void doRun() { execute(); } }, (random.nextInt(30) + 60) * MINUTE, TimeUnit.MILLISECONDS); }
Timer.get().scheduleAtFixedRate(new SafeTimerTask() { @Override protected void doRun() throws Exception {
/** * Schedule a TimerTask according to the two constants above. * * @param trigger the trigger associated with the task * @param timerTask the TimerTask to be scheduled */ public void schedule(GerritTriggerTimerTask timerTask, @Nonnull GerritTrigger trigger) { long timerPeriod = TimeUnit2.SECONDS.toMillis(calculateDynamicConfigRefreshInterval(trigger)); try { logger.debug("Schedule task " + timerTask + " for every " + timerPeriod + "ms"); jenkins.util.Timer.get().scheduleWithFixedDelay(timerTask, DELAY_MILLISECONDS, timerPeriod, TimeUnit.MILLISECONDS); } catch (IllegalArgumentException iae) { logger.error("Attempted use of negative delay", iae); } catch (IllegalStateException ise) { logger.error("Attempted re-use of TimerTask", ise); } } }
/** * Like {@link #getStatus} but more robust. * Waits a most a given amount of time for the result, and handles {@link RuntimeException}s. * @param timeout maximum amount of time to spend * @param unit time unit */ public final @CheckForNull String getStatusBounded(long timeout, TimeUnit unit) { Future<String> task = null; try { task = Timer.get().submit(new Callable<String>() { @Override public String call() throws Exception { return getStatus(); } }); return task.get(timeout, unit); } catch (Exception x) { // ExecutionException, RejectedExecutionException, CancellationException, TimeoutException, InterruptedException if (task != null) { task.cancel(true); // in case of TimeoutException especially, we do not want this thread continuing } LOGGER.log(Level.FINE, "failed to check status of " + super.toString(), x); return x.toString(); } }
private void _cleanUpShutdownTimer(List<Throwable> errors) { LOGGER.log(Level.FINE, "Shutting down timer"); try { Timer.shutdown(); } catch (SecurityException e) { LOGGER.log(WARNING, "Not permitted to shut down Timer", e); errors.add(e); } catch (OutOfMemoryError e) { // we should just propagate this, no point trying to log throw e; } catch (LinkageError e) { LOGGER.log(SEVERE, "Failed to shut down Timer", e); // safe to ignore and continue for this one } catch (Throwable e) { LOGGER.log(SEVERE, "Failed to shut down Timer", e); // save for later errors.add(e); } }
private void push() { if (DELAY_SECONDS < 0) return; synchronized (lock) { // Can be done or canceled in case of a bug or external intervention - do not allow it to hang there forever if (nextSave != null && !(nextSave.isDone() || nextSave.isCancelled())) return; nextSave = Timer.get().schedule(this, DELAY_SECONDS, TimeUnit.SECONDS); } }
private void schedule(long interval) { Timer.get() .scheduleAtFixedRate(new SafeTimerTask() { public void doRun() { triggerUpdate(); } }, interval, interval, TimeUnit.MILLISECONDS); }
/** * Like {@link #getStatus} but more robust. * Waits a most a given amount of time for the result, and handles {@link RuntimeException}s. * @param timeout maximum amount of time to spend * @param unit time unit */ public final @CheckForNull String getStatusBounded(long timeout, TimeUnit unit) { Future<String> task = null; try { task = Timer.get().submit(new Callable<String>() { @Override public String call() throws Exception { return getStatus(); } }); return task.get(timeout, unit); } catch (Exception x) { // ExecutionException, RejectedExecutionException, CancellationException, TimeoutException, InterruptedException if (task != null) { task.cancel(true); // in case of TimeoutException especially, we do not want this thread continuing } LOGGER.log(Level.FINE, "failed to check status of " + super.toString(), x); return x.toString(); } }