Search in sources :

Example 51 with ScheduledThreadPoolExecutor

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);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 52 with ScheduledThreadPoolExecutor

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) ;
}
Also used : HistogramLogWriter(org.HdrHistogram.HistogramLogWriter) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SimplePauseDetector(org.LatencyUtils.SimplePauseDetector)

Example 53 with ScheduledThreadPoolExecutor

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;
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 54 with ScheduledThreadPoolExecutor

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);
}
Also used : Service(org.jboss.msc.service.Service) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) AsynchronousServiceBuilder(org.wildfly.clustering.service.AsynchronousServiceBuilder) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService) ServiceController(org.jboss.msc.service.ServiceController) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServiceName(org.jboss.msc.service.ServiceName) ServiceTarget(org.jboss.msc.service.ServiceTarget) JBossExecutors(org.jboss.threads.JBossExecutors) ThreadFactory(java.util.concurrent.ThreadFactory) Builder(org.wildfly.clustering.service.Builder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SuppliedValueService(org.wildfly.clustering.service.SuppliedValueService)

Example 55 with ScheduledThreadPoolExecutor

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;
}
Also used : ClassLoaderThreadFactory(org.wildfly.clustering.service.concurrent.ClassLoaderThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) ThreadPoolExecutorFactory(org.infinispan.commons.executors.ThreadPoolExecutorFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ClassLoaderThreadFactory(org.wildfly.clustering.service.concurrent.ClassLoaderThreadFactory)

Aggregations

ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)154 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)31 Test (org.junit.Test)26 ExecutorService (java.util.concurrent.ExecutorService)24 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)22 ThreadFactory (java.util.concurrent.ThreadFactory)15 Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)12 List (java.util.List)10 HashMap (java.util.HashMap)9 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)8 NettyClientMetrics (com.linkedin.pinot.transport.metrics.NettyClientMetrics)8 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)8 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)8 HashedWheelTimer (io.netty.util.HashedWheelTimer)8 File (java.io.File)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)7 IOException (java.io.IOException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7