JavaMelody uses a custom RrdNioBackendFactory,
in order to use its own and cancelable file sync timer.
@param timer Timer
@throws IOException e
198739
public static void initBackendFactory(Timer timer) throws IOException {
		RrdNioBackend.setFileSyncTimer(timer);

		try {
			if (!RrdBackendFactory.getDefaultFactory().getFactoryName()
					.equals(RrdNioBackendFactory.FACTORY_NAME)) {
				RrdBackendFactory.registerAndSetAsDefaultFactory(new RrdNioBackendFactory());
			}
		} catch (final RrdException e) {
			throw createIOException(e);
		}
	}
895497
public static void removeTimersByJ2EEName(J2EEName j2eeName)
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "removeTimersByJ2EEName: " + j2eeName);

        Collection<TimerNpImpl> timersToRemove = null;

        // Although this seems inefficient, removing all of the timers for an
        // application or module that is stopping is done in two steps to avoid
        // obtaining locks on both the active timers map and any individual
        // timer concurrently. Many methods on a timer will also need to obtain
        // the lock on the active timers map as well, so the two step approach
        // avoids the possibility of deadlock.                           RTC107334

        synchronized (svActiveTimers)
        {
            if (svActiveTimers.size() > 0)
            {
                String appToRemove = j2eeName.getApplication();
                String modToRemove = j2eeName.getModule();

                for (TimerNpImpl timer : svActiveTimers.values())
                {
                    J2EEName timerJ2EEName = timer.ivBeanId.j2eeName;
                    if (appToRemove.equals(timerJ2EEName.getApplication()) &&
                        (modToRemove == null || modToRemove.equals(timerJ2EEName.getModule())))
                    {
                        // save the timer to be removed outside the active timers map lock
                        if (timersToRemove == null)
                        {
                            timersToRemove = new ArrayList<TimerNpImpl>();
                        }
                        timersToRemove.add(timer);
                    }
                }
            }
        }

        if (timersToRemove != null)
        {
            for (TimerNpImpl timer : timersToRemove)
            {
                timer.remove(true); // permanently remove the timer; cannot be rolled back
            }
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "removeTimersByJ2EEName: removed " + (timersToRemove != null ? timersToRemove.size() : 0));
    }
1345768
@Override
    public void close(byte[] tail) throws IOException {
        synchronized (fileStream) {
            // Cancel timer thread before any method capable of throwing IOException.
            if (flushTimer != null) {
                flushTimer.cancel();
                flushTimer = null;
            }
            fileStream.flush();
            fileStream.close();
        }
    }
445922
public void reportTimer(Timer timer) {
    LOGGER.debug("+++ entering UnsortedWriterReportVisitor.reportTimer +++");

    long count = timer.getCount();
    long timersum = timer.getTimerSum();
    String result = timer.getName() + " timer : count = " + count + ", timerSum = " + timersum + ", mean = " +
      ((double) timersum / count);
    writeStringToWriter(result);
  }
1312414
private void saveRegisterWatermarkTimer() {
		long currentWatermark = timerService.currentWatermark();
		// protect against overflow
		if (currentWatermark + 1 > currentWatermark) {
			timerService.registerEventTimeTimer(VoidNamespace.INSTANCE, currentWatermark + 1);
		}
	}
519549
Optional<String> writeTimer(Timer timer) {
        return Optional.of(writeDocument(timer, builder -> {
            builder.append(",\"count\":").append(timer.count());
            builder.append(",\"sum\":").append(timer.totalTime(getBaseTimeUnit()));
            builder.append(",\"mean\":").append(timer.mean(getBaseTimeUnit()));
            builder.append(",\"max\":").append(timer.max(getBaseTimeUnit()));
        }));
    }
532139
public synchronized void checkIfCreateNonPersistentTimerAllowed(EJBModuleMetaDataImpl mmd) {
        if (ivStopping) {
            throw new EJBStoppedException(ivName);
        }

        if (mmd != null && mmd.ivStopping) {
            throw new EJBStoppedException(mmd.getJ2EEName().toString());
        }
    }
433535
void addAutomaticTimer(AutomaticTimer timer)
    {
        timer.ivMethod = this;
        ivAutomaticTimers.add(timer);

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "added automatic timer: " + timer);
    }
1315366
public static RejectedExecutionHandler backoff(final int retries, long backoffAmount, TimeUnit unit) {
        ObjectUtil.checkPositive(retries, "retries");
        final long backOffNanos = unit.toNanos(backoffAmount);
        return new RejectedExecutionHandler() {
            @Override
            public void rejected(Runnable task, SingleThreadEventExecutor executor) {
                if (!executor.inEventLoop()) {
                    for (int i = 0; i < retries; i++) {
                        // Try to wake up the executor so it will empty its task queue.
                        executor.wakeup(false);

                        LockSupport.parkNanos(backOffNanos);
                        if (executor.offerTask(task)) {
                            return;
                        }
                    }
                }
                // Either we tried to add the task from within the EventLoop or we was not able to add it even with
                // backoff.
                throw new RejectedExecutionException();
            }
        };
    }
624889
public synchronized void onTimer() {
        CruiseConfig currentConfig = applicationContext.getBean(CruiseConfigProvider.class).getCurrentConfig();
        purgeStaleHealthMessages(currentConfig);
        LOG.debug("Recomputing material to pipeline mappings.");

        HashMap<ServerHealthState, Set<String>> erroredPipelines = new HashMap<>();

        for (Map.Entry<HealthStateType, ServerHealthState> entry : serverHealth.entrySet()) {
            erroredPipelines.put(entry.getValue(), entry.getValue().getPipelineNames(currentConfig));
        }
        pipelinesWithErrors = erroredPipelines;
        LOG.debug("Done recomputing material to pipeline mappings.");
    }
174364
private void startAppendTimer() {
    // Set a timer that will be used to periodically synchronize with other nodes
    // in the cluster. This timer acts as a heartbeat to ensure this node remains
    // the leader.
    LOGGER.trace("{} - Starting append timer", context.getCluster().member().address());
    appendTimer = context.getThreadContext().schedule(Duration.ZERO, context.getHeartbeatInterval(), this::appendMembers);
  }
302202
public boolean syncClonedListener(BaseField field, FieldListener listener, boolean bInitCalled)
    {
        if (!bInitCalled)
            ((DateUpdatedHandler)listener).init(null, m_iMainFilesFieldSeq, m_bMoveCurrentTime);
        return super.syncClonedListener(field, listener, true);
    }
1095093
@Override
  public void cancel(Serializable f) {
    if (f != null && f instanceof TimerTaskHandle) {
      TimerTaskHandle timerTaskHandle = (TimerTaskHandle) f;
      if (timerTaskHandle.future != null) {
        logger.debug("Cancelling timer with id [{}] and delay [{}]", timerTaskHandle.id, timerTaskHandle.future.getDelay(TimeUnit.MILLISECONDS));
        if (executor.remove((Runnable) timerTaskHandle.future)) {
          timerTaskHandle.future.cancel(false);
          returnTimerTaskHandle(timerTaskHandle);
        }
      }
    }
  }
529372
private void scheduleCreateRemoteListener() {

        final String methodName = "scheduleCreateRemoteListener";
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, methodName);
        }

        _timer.schedule(new TimerTask() {

            public void run() {

                createRemoteListenerDeactivateOnException(false);

                synchronized(SibRaStaticDestinationEndpointActivation.this) {

                    if (_remoteConnection != null) {

                        /*
                         * Successfully created a connection
                         */

                        SibTr.info(TRACE, "CONNECTED_CWSIV0777", new Object[] {
                                _remoteConnection.getConnection().getMeName(),
                                _endpointConfiguration.getDestination()
                                        .getDestinationName(),
                                _endpointConfiguration.getBusName(),
                                SibRaStaticDestinationEndpointActivation.this });

                    }

                }

            }
        }, RETRY_INTERVAL);

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, methodName);
        }

    }
498855
private function scheduleTimer(TimerInterface $timer)
    {
        $flags = Event::TIMEOUT;

        if ($timer->isPeriodic()) {
            $flags |= Event::PERSIST;
        }

        $event = new Event($this->eventBase, -1, $flags, $this->timerCallback, $timer);
        $this->timerEvents[$timer] = $event;

        $event->add($timer->getInterval());
    }
724453
public void addTimer(long timeout, IPollEvents sink, int id)
    {
        assert (Thread.currentThread() == worker);

        final long expiration = clock() + timeout;
        TimerInfo info = new TimerInfo(sink, id);
        timers.insert(expiration, info);

        changed = true;
    }
1144297
public synchronized void schedule()
    {
        // Avoid scheduling a timer that was destroyed on another thread and
        // avoid scheduling a timer twice, which might be attempted if two
        // threads concurrently attempt to cancel and then both rollback.
        if (ivTaskHandler == null && !ivDestroyed)
        {
            // Create the timer task handler (Runnable/Listener) and schedule the task
            ivTaskHandler = ivContainer.getEJBRuntime().createNonPersistentTimerTaskHandler(this);

            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "schedule: scheduling timer for " + ivExpiration + " / " + new Date(ivExpiration));

            ivTaskHandler.schedule(ivExpiration);
        }
        else
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "schedule: timer already scheduled or destroyed : destroyed=" + ivDestroyed);
        }
    }