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) 

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:com.dsf.dbxtract.cdc.App.java

/**
 * Starts scanning services./*from  w  ww  .ja v  a2 s.  c om*/
 * 
 * @throws ConfigurationException
 *             any configuration error
 */
public void start() throws ConfigurationException {

    // Get ZooKeeper's connection string
    String zkConnection = config.getZooKeeper();

    // Get interval (in milliseconds) between executions
    long interval = config.getDataSources().getInterval();

    scheduledService = Executors.newScheduledThreadPool(config.getThreadPoolSize());

    // Prepare the task's list. Each handler becomes a task.
    for (JournalHandler handler : config.getHandlers()) {

        Runnable executor = new JournalExecutor(config.getAgentName(), zkConnection, handler,
                config.getSourceByHandler(handler));
        scheduledService.scheduleAtFixedRate(executor, 0L, interval, TimeUnit.MILLISECONDS);
    }
}

From source file:com.ntsync.android.sync.activities.PaymentVerificationService.java

/**
 * Starts PaymentData Verification Timer, if not already running and
 * PaymentData is open to verify/*from  w ww. jav a 2s  .  co  m*/
 * */
public static void startVerificationTimer(final Context context) {
    if (SyncUtils.hasPaymentData(context)) {
        ScheduledExecutorService scheduler = SCHEDULER_REF.get();
        if (scheduler == null || scheduler.isShutdown()) {
            scheduler = Executors.newScheduledThreadPool(1);
            SCHEDULER_REF.set(scheduler);
        } else {
            // Timer aktiv
            return;
        }
        final ScheduledExecutorService sched = scheduler;

        final Runnable verifTimer = new Runnable() {
            public void run() {
                runVerifier(context, sched);
            }
        };
        // Verificate PaymentData every 1h for

        scheduler.scheduleAtFixedRate(verifTimer, VERIFICATION_INITIAL_DELAY, VERIFICATION_INTERVAL,
                TimeUnit.SECONDS);
    }
}

From source file:outfox.dict.contest.service.CrontabService.java

@PostConstruct
public void init() {
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(ContestConsts.CORE_POOL_SIZE);
    executor.scheduleAtFixedRate(new SingerInfoUpdate(), 0, ContestConsts.CRONTAB_TIME, TimeUnit.DAYS);
    // ???Zzzz//from  w w  w .  j a v a  2 s.  c o  m
    // loadingPreparedBarrage();
}

From source file:com.vmware.photon.controller.cloudstore.xenon.entity.IpLeaseServiceTest.java

@BeforeSuite
public void beforeSuite() throws Throwable {
    host = BasicServiceHost.create();/*  www.j av a2s  . co  m*/
    ServiceHostUtils.startFactoryServices(host, CloudStoreServiceGroup.FACTORY_SERVICES_MAP);

    StaticServerSet serverSet = new StaticServerSet(
            new InetSocketAddress(host.getPreferredAddress(), host.getPort()));
    xenonClient = new XenonRestClient(serverSet, Executors.newFixedThreadPool(128),
            Executors.newScheduledThreadPool(1), host);
    xenonClient.start();
}

From source file:com.vmware.photon.controller.cloudstore.xenon.entity.DhcpSubnetServiceTest.java

@BeforeSuite
public void beforeSuite() throws Throwable {
    host = BasicServiceHost.create();//from  w ww. ja v  a 2 s.co m
    ServiceHostUtils.startFactoryServices(host, CloudStoreServiceGroup.FACTORY_SERVICES_MAP);

    StaticServerSet serverSet = new StaticServerSet(
            new InetSocketAddress(host.getPreferredAddress(), host.getPort()));
    xenonClient = new XenonRestClient(serverSet, Executors.newFixedThreadPool(128),
            Executors.newScheduledThreadPool(1));
    xenonClient.start();
}

From source file:com.netflix.conductor.core.execution.WorkflowSweeper.java

public void init(WorkflowExecutor workflowProvider) {

    ScheduledExecutorService deciderPool = Executors.newScheduledThreadPool(1);

    deciderPool.scheduleWithFixedDelay(() -> {

        try {//from w w w .ja va  2  s .  c o m

            if (config.disableSweep()) {
                logger.info("Workflow sweep is disabled.");
                return;
            }
            List<String> workflowIds = queues.pop(WorkflowExecutor.deciderQueue, 2 * executorThreadPoolSize,
                    2000);
            sweep(workflowIds, workflowProvider);

        } catch (Exception e) {
            Monitors.error(className, "sweep");
            logger.error(e.getMessage(), e);

        }

    }, 500, 500, TimeUnit.MILLISECONDS);
}

From source file:org.apache.stratos.cartridge.agent.registrant.RegistrantHealthChecker.java

public RegistrantHealthChecker(RegistrantDatabase database, ClusteringClient clusteringClient,
        ConfigurationContext configurationContext, int healthCheckInterval, int threadPoolSize) {
    this.database = database;
    this.clusteringClient = clusteringClient;
    this.configurationContext = configurationContext;
    this.healthCheckInterval = healthCheckInterval;
    scheduler = Executors.newScheduledThreadPool(threadPoolSize);
}

From source file:org.wicketstuff.nashorn.resource.NashornResourceReference.java

/**
 * Creates a nashorn resource reference with the given name
 * /* w w  w.j av a  2 s  .  c o  m*/
 * @param name
 *            the name of the nashorn resource reference
 * @param coreSize
 *            the core size of the script execution pool
 * @param delay
 *            the delay until a script execution is going to be terminated
 * @param delayUnit
 *            the unit until a script execution is going to be terminated
 */
public NashornResourceReference(String name, int coreSize, long delay, TimeUnit delayUnit) {
    super(name);
    scheduledExecutorService = Executors.newScheduledThreadPool(coreSize);
    this.delay = delay;
    this.delayUnit = delayUnit;
}

From source file:com.mmj.app.biz.service.impl.UserServiceImpl.java

@PostConstruct
public void cronCache() {
    ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1);
    newScheduledThreadPool.scheduleAtFixedRate(new Runnable() {

        @Override/*from   ww w . j  a v  a2  s .  co m*/
        public void run() {
            try {
                init();
            } catch (Throwable e) {
                logger.error("init memberCacheMap error", e);
            }
        }

    }, 50, 12 * 60 * 60, TimeUnit.SECONDS);
}

From source file:scouter.plugin.server.alert.telegram.TelegramPlugin.java

public TelegramPlugin() {
    if (ai.incrementAndGet() == 1) {
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

        // thread count check
        executor.scheduleAtFixedRate(new Runnable() {
            @Override// w w w. ja v  a  2s.  c  om
            public void run() {
                for (int objHash : javaeeObjHashList) {
                    try {
                        if (AgentManager.isActive(objHash)) {
                            ObjectPack objectPack = AgentManager.getAgent(objHash);
                            MapPack mapPack = new MapPack();
                            mapPack.put("objHash", objHash);

                            mapPack = AgentCall.call(objectPack, RequestCmd.OBJECT_THREAD_LIST, mapPack);

                            int threadCountThreshold = conf.getInt("ext_plugin_thread_count_threshold", 0);
                            int threadCount = mapPack.getList("name").size();

                            if (threadCountThreshold != 0 && threadCount > threadCountThreshold) {
                                AlertPack ap = new AlertPack();

                                ap.level = AlertLevel.WARN;
                                ap.objHash = objHash;
                                ap.title = "Thread count exceed a threshold.";
                                ap.message = objectPack.objName + "'s Thread count(" + threadCount
                                        + ") exceed a threshold.";
                                ap.time = System.currentTimeMillis();
                                ap.objType = objectPack.objType;

                                alert(ap);
                            }
                        }
                    } catch (Exception e) {
                        // ignore
                    }
                }
            }
        }, 0, 5, TimeUnit.SECONDS);
    }
}