Example usage for java.util.concurrent Executors newScheduledThreadPool

List of usage examples for java.util.concurrent Executors newScheduledThreadPool

Introduction

In this page you can find the example usage for java.util.concurrent Executors newScheduledThreadPool.

Prototype

public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory) 

Source Link

Document

Creates a thread pool that can schedule commands to run after a given delay, or to execute periodically.

Usage

From source file:eu.smartenit.sbox.main.SBox.java

/**
 * The main method.//from   w  w w.  ja v a 2  s. c  o  m
 * 
 *  @param args The main method arguments
 * 
 */
public static void main(String[] args) {
    logger.info("Initialing SBox service.");

    // Read configuration parameters from file.
    readConfigurationProperties();

    // Set db file url.
    DbConstants.DBI_URL = "jdbc:sqlite:" + SBoxProperties.DB_FILE;

    // Initialize threads pool.
    threadFactory = new ThreadFactory();
    SBoxThreadHandler.threadService = Executors.newScheduledThreadPool(SBoxProperties.CORE_POOL_SIZE,
            threadFactory);

    // Initialize network traffic manager with default mode.
    NetworkTrafficManager ntm = new NetworkTrafficManager();
    ntm.initialize();

    // Initialize inter-sbox server at configured port and constructed NTM.
    new InterSBoxServer(SBoxProperties.INTER_SBOX_PORT, ntm);

    // Initialize economic analyzer.
    EconomicAnalyzer eca = new EconomicAnalyzer(ntm.getDtmTrafficManager());

    // Initialize qos analyzer.
    DTMQosAnalyzer analyzer = new DTMQosAnalyzer(ntm.getDtmTrafficManager(), eca);
    analyzer.initialize();

}

From source file:Main.java

public static ScheduledExecutorService newFixedThreadScheduledPool(int qty, String processName) {
    return Executors.newScheduledThreadPool(qty, newThreadFactory(processName));
}

From source file:Main.java

public static ScheduledExecutorService createStatisticsExecutor() {
    return Executors.newScheduledThreadPool(Integer.getInteger(ORG_EHCACHE_STATISTICS_EXECUTOR_POOL_SIZE, 1),
            new ThreadFactory() {
                private AtomicInteger cnt = new AtomicInteger(0);

                @Override//from w ww  .  j  a va 2 s  .c o m
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r, "Statistics Thread-" + cnt.incrementAndGet());
                    t.setDaemon(true);
                    return t;
                }
            });
}

From source file:Main.java

public static ScheduledExecutorService newFixedThreadScheduledPool(int nThreads, String processName,
        boolean isDaemon) {
    return Executors.newScheduledThreadPool(nThreads, newThreadFactory(processName, isDaemon));
}

From source file:com.nebhale.cyclinglibrary.util.UtilConfiguration.java

@Bean
ScheduledExecutorService executorService() {
    return Executors.newScheduledThreadPool(5, new CustomizableThreadFactory("point-augmenter-"));
}

From source file:pzalejko.iot.hardware.home.core.service.DefaultTaskExecutor.java

public DefaultTaskExecutor() {
    this(Executors.newScheduledThreadPool(THREAD_POOL_SIZE, new InternalThreadFactory()),
            Executors.newCachedThreadPool(new InternalThreadFactory()));

}

From source file:org.apache.synapse.commons.throttle.core.ThrottleContextCleanupTask.java

public ThrottleContextCleanupTask() {

    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1, new ThreadFactory() {

        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName("Throttle Cleanup Task");
            return t;
        }//w  w w . j a  va  2s .  com
    });

    String throttleFrequency = System.getProperty(THROTTLE_CONTEXT_CLEANUP_TASK_FREQUENCY);
    if (throttleFrequency == null) {
        throttleFrequency = "3600000";
    }

    if (log.isDebugEnabled()) {
        log.debug("Throttling Cleanup Task Frequency set to " + throttleFrequency);
    }

    executor.scheduleAtFixedRate(new CleanupTask(), Integer.parseInt(throttleFrequency),
            Integer.parseInt(throttleFrequency), TimeUnit.MILLISECONDS);

}

From source file:com.stimulus.util.TempFiles.java

public TempFiles() {
    scheduler = Executors.newScheduledThreadPool(1, ThreadUtil.getDaemonThreadFactory("tempfiles"));

}

From source file:org.apache.stratos.usage.agent.persist.UsageDataPersistenceManager.java

public UsageDataPersistenceManager(UsageAgentConfiguration configuration) {
    scheduler = Executors.newScheduledThreadPool(2, new UsageDataPersistenceThreadFactory());
    this.configuration = configuration;
}

From source file:org.thingsplode.agent.monitors.MonitoringExecutor.java

@PostConstruct
public void init() {
    scheduler = Executors.newScheduledThreadPool(schedulerThreadPoolSize, (Runnable r) -> {
        Thread t = new Thread(r, "SCHEDULER");
        t.setDaemon(true);/* ww w .  j a  v a2 s .c om*/
        t.setUncaughtExceptionHandler((Thread t1, Throwable e) -> {
            logger.error(String.format("Uncaught exception on thread %s. Exception %s with message %s.",
                    t1.getName(), e.getClass().getSimpleName(), e.getMessage()), e);
        });
        return t;
    });
    if (autoInitializeSystemMetricProvider) {
        addProvider(new SystemMetricProvider(), 60);
    }
    if (autoInitializeThreadMetricProvider) {
        addProvider(new ThreadMetricProvider(), 300);
    }
    scheduleProviders();
}