@Override public synchronized void runTimer() throws Exception { tasks.defaultExecutor().start(this::collectMetrics); }
@Override public void runTimer() throws Exception { tasks.defaultExecutor().start(this::runEviction); }
@Override protected String doWork() throws Exception { long now = System.currentTimeMillis(); int numScheduled = 0; synchronized (waitingTasks) { Iterator<WaitingTask> iter = waitingTasks.iterator(); while (iter.hasNext()) { WaitingTask next = iter.next(); if (next.timeout > now) { return numScheduled > 0 ? "Re-Scheduled Tasks: " + numScheduled : null; } iter.remove(); tasks.executor(next.executor).start(next); numScheduled++; } } return null; }
@Override public void runTimer() throws Exception { tasks.defaultExecutor().start(() -> Sirius.getSetup().cleanOldLogFiles(logFileRetention.toMillis())); } }
/** * Calls {@link #executeWork()} in the determined executor. * <p> * This is kind of the main loop, as {@code executeWork()} will call {@code loop()} once the computation * ({@code doWork()} is finished. Using {@link ExecutionBuilder#frequency(Object, double)} this is limited to the * call frequency as determined by {@code maxCallFrequency()}. */ protected void loop() { tasks.executor(determineExecutor()).frequency(this, maxCallFrequency()).start(this::executeWork); }
/** * Updates the entity in the database asynchronous using a dedicated thread pool. * * @param entity the entity to be written into the DB * @param <E> the type of the entity to update * @return a {@link Promise} handling the update process */ public <E extends Entity> Promise<E> updateAsync(E entity) { Promise<E> promise = new Promise<>(); tasks.executor(ASYNC_UPDATER).start(() -> { try { update(entity); promise.success(entity); } catch (Exception e) { promise.fail(e); } }); return promise; }
private void executeTask(final TimedTask task) { tasks.executor(TIMER) .dropOnOverload(() -> Exceptions.handle() .to(LOG) .withSystemErrorMessage( "Dropping timer task '%s' (%s) due to system overload!", task, task.getClass()) .handle()) .start(() -> { try { Watch w = Watch.start(); task.runTimer(); if (w.elapsed(TimeUnit.SECONDS, false) > 1) { LOG.WARN("TimedTask '%s' (%s) took over a second to complete! " + "Consider executing the work in a separate executor!", task, task.getClass()); } } catch (Exception t) { Exceptions.handle(LOG, t); } }); }
protected void handlePubSubMessage(String channel, String message, Subscriber subscriber) { tasks.executor("redis-pubsub").start(() -> { Watch w = Watch.start(); try { subscriber.onMessage(message); } catch (Exception e) { Exceptions.handle() .to(LOG) .error(e) .withSystemErrorMessage("Failed to process a message '%s' for topic '%s': %s (%s)", message, subscriber.getTopic()) .handle(); } w.submitMicroTiming("redis", channel); messageDuration.addValue(w.elapsedMillis()); }); }