use of java.util.concurrent.ScheduledThreadPoolExecutor in project druid by alibaba.
the class MonitorClient method start.
public void start() {
checkInst();
if (scheduler == null) {
scheduler = new ScheduledThreadPoolExecutor(schedulerThreadSize);
}
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
collectSql();
}
}, timeBetweenSqlCollect, timeBetweenSqlCollect, timeUnit);
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
collectSpringMethod();
}
}, timeBetweenSpringCollect, timeBetweenSpringCollect, timeUnit);
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
collectWebURI();
}
}, timeBetweenWebUriCollect, timeBetweenWebUriCollect, timeUnit);
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project LatencyUtils by LatencyUtils.
the class LatencyLoggingDemo method main.
public static void main(final String[] args) throws FileNotFoundException {
// Knowing that we're using a SimplePauseDetector, set it to verbose so that the user can see
// the pause detection messages:
((SimplePauseDetector) latencyStats.getPauseDetector()).setVerbose(true);
final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
// Record latencies on a "regular" basis. This will tend to record semi-reliably at
// each interval as long as the JVM doesn't stall.
executor.scheduleWithFixedDelay(new Recorder(), RECORDING_INTERVAL, RECORDING_INTERVAL, TimeUnit.NANOSECONDS);
histogramLogWriter = new HistogramLogWriter(fillInPidAndDate(defaultLogFileName));
histogramLogWriter.outputComment("[Logged with LatencyLoggingDemo]");
histogramLogWriter.outputLogFormatVersion();
reportingStartTime = System.currentTimeMillis();
// Force an interval sample right at the reporting start time (to start samples here):
latencyStats.getIntervalHistogram();
histogramLogWriter.outputStartTime(reportingStartTime);
histogramLogWriter.outputLegend();
// Regularly report on observations into log file:
executor.scheduleWithFixedDelay(new Reporter(), REPORTING_INTERVAL, REPORTING_INTERVAL, TimeUnit.NANOSECONDS);
while (true) ;
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project wildfly by wildfly.
the class SessionExpirationScheduler method createScheduledExecutor.
private static ScheduledExecutorService createScheduledExecutor(ThreadFactory factory) {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, factory);
executor.setRemoveOnCancelPolicy(true);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
return executor;
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project wildfly by wildfly.
the class RemoveOnCancelScheduledExecutorServiceBuilder method build.
@Override
public ServiceBuilder<ScheduledExecutorService> build(ServiceTarget target) {
Function<ScheduledExecutorService, ScheduledExecutorService> mapper = executor -> JBossExecutors.protectedScheduledExecutorService(executor);
Supplier<ScheduledExecutorService> supplier = () -> {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.size, this.factory);
executor.setRemoveOnCancelPolicy(true);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
return executor;
};
Service<ScheduledExecutorService> service = new SuppliedValueService<>(mapper, supplier, ScheduledExecutorService::shutdown);
return new AsynchronousServiceBuilder<>(this.name, service).startSynchronously().build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project wildfly by wildfly.
the class ScheduledThreadPoolBuilder method configure.
@Override
public Builder<ThreadPoolConfiguration> configure(OperationContext context, ModelNode model) throws OperationFailedException {
int maxThreads = this.definition.getMaxThreads().resolveModelAttribute(context, model).asInt();
long keepAliveTime = this.definition.getKeepAliveTime().resolveModelAttribute(context, model).asLong();
ThreadPoolExecutorFactory<?> factory = new ThreadPoolExecutorFactory<ScheduledExecutorService>() {
@Override
public ScheduledExecutorService createExecutor(ThreadFactory factory) {
// Use fixed size, based on maxThreads
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(maxThreads, new ClassLoaderThreadFactory(factory, ClassLoaderThreadFactory.class.getClassLoader()));
executor.setKeepAliveTime(keepAliveTime, TimeUnit.MILLISECONDS);
executor.setRemoveOnCancelPolicy(true);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
return executor;
}
@Override
public void validate() {
// Do nothing
}
};
this.builder.threadPoolFactory(factory);
return this;
}
Aggregations