Example usage for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor

List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor

Introduction

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

Prototype

public ScheduledThreadPoolExecutor(int corePoolSize) 

Source Link

Document

Creates a new ScheduledThreadPoolExecutor with the given core pool size.

Usage

From source file:net.firejack.platform.web.statistics.engine.BufferScheduleSwitcher.java

/***/
public void scheduleTasks() {
    executorService = new ScheduledThreadPoolExecutor(2);
    executorService.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);

    //        Calendar calendar = DateTimeUtils.getSynchTime(synchTime);
    //        if (calendar.before(Calendar.getInstance())) {
    //            calendar.add(Calendar.DAY_OF_MONTH, 1);
    //        }//w w w.j  a  v  a2 s .  co m
    //        long delay = calendar.getTimeInMillis() - System.currentTimeMillis();
    long delay = 0;
    executorService.scheduleAtFixedRate(new ImportTask(), delay, DateUtils.MILLIS_PER_DAY,
            TimeUnit.MILLISECONDS);
}

From source file:com.thoughtworks.go.remote.work.ConsoleOutputTransmitter.java

public ConsoleOutputTransmitter(ConsoleAppender consoleAppender) {
    this(consoleAppender, new SystemEnvironment().getConsolePublishInterval(),
            new ScheduledThreadPoolExecutor(1));
}

From source file:com.bia.yahoomailjava.YahooMailService.java

private YahooMailService() {
    executor = new ScheduledThreadPoolExecutor(2);
}

From source file:de.th_ht.ambilike.HueListener.java

public HueListener(Context context, HuePreferences_ preferences, HueController hueController,
        HueNotification hueNotification) {
    this.context = context;
    this.preferences = preferences;
    this.hueController = hueController;
    this.hueNotification = hueNotification;
    scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
}

From source file:com.twitter.distributedlog.config.TestDynamicConfigurationFactory.java

private DynamicConfigurationFactory getConfigFactory(File configFile) {
    String streamConfigPath = configFile.getParent();
    ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1);
    ConcurrentBaseConfiguration defaultConf = new ConcurrentConstConfiguration(
            new DistributedLogConfiguration());
    return new DynamicConfigurationFactory(executorService, 100, TimeUnit.MILLISECONDS);
}

From source file:com.bia.gmailjava.EmailService.java

private EmailService() {
    executor = new ScheduledThreadPoolExecutor(2);
}

From source file:org.jmangos.commons.threadpool.CommonThreadPoolManager.java

/**
 * @see org.jmangos.commons.service.Service#start()
 *///w w  w. j av a 2 s  . c om
@PostConstruct
@Override
public void start() {

    final int scheduledPoolSize = ThreadPoolConfig.GENERAL_POOL;
    this.scheduledPool = new ScheduledThreadPoolExecutor(scheduledPoolSize);
    this.scheduledPool.prestartAllCoreThreads();

    final int instantPoolSize = ThreadPoolConfig.GENERAL_POOL;
    this.instantPool = new ThreadPoolExecutor(instantPoolSize, instantPoolSize, 0, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(100000));
    this.instantPool.prestartAllCoreThreads();
}

From source file:com.l2jfree.util.concurrent.L2ThreadPool.java

public static void initThreadPools(ThreadPoolInitializer initializer) throws Exception {
    if (!ArrayUtils.isEmpty(_scheduledPools) || !ArrayUtils.isEmpty(_instantPools)
            || !ArrayUtils.isEmpty(_longRunningPools))
        throw new Exception("The thread pool has been already set!");

    initializer.initThreadPool();//from   www . j  a v  a2  s .  co  m

    _scheduledPools = initializer.getScheduledPools();
    _instantPools = initializer.getInstantPools();
    _longRunningPools = initializer.getLongRunningPools();

    if (ArrayUtils.isEmpty(_scheduledPools)) {
        _log.info("No scheduled thread pool has been manually initialized, so initializing default one.");

        _scheduledPools = new ScheduledThreadPoolExecutor[] { new ScheduledThreadPoolExecutor( //
                // int corePoolSize
                4) };
    }

    if (ArrayUtils.isEmpty(_instantPools)) {
        _log.info("No instant thread pool has been manually initialized, so initializing default one.");

        _instantPools = new ThreadPoolExecutor[] { new ThreadPoolExecutor( //
                // int corePoolSize
                0,
                // int maximumPoolSize
                Integer.MAX_VALUE,
                // long keepAliveTime
                60L,
                // TimeUnit unit
                TimeUnit.SECONDS,
                // BlockingQueue<Runnable> workQueue
                new SynchronousQueue<Runnable>()) };
    }

    if (ArrayUtils.isEmpty(_longRunningPools)) {
        _log.info("No long running thread pool has been manually initialized, so initializing default one.");

        _longRunningPools = new ThreadPoolExecutor[] { new ThreadPoolExecutor( //
                // int corePoolSize
                0,
                // int maximumPoolSize
                Integer.MAX_VALUE,
                // long keepAliveTime
                60L,
                // TimeUnit unit
                TimeUnit.SECONDS,
                // BlockingQueue<Runnable> workQueue
                new SynchronousQueue<Runnable>()) };
    }

    for (ThreadPoolExecutor threadPool : getThreadPools()) {
        threadPool.setRejectedExecutionHandler(new L2RejectedExecutionHandler());
        threadPool.prestartAllCoreThreads();
    }

    scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            purge();
        }
    }, 60000, 60000);

    _log.info("L2ThreadPool: Initialized with");
    _log.info("\t... " + getPoolSize(_scheduledPools) + "/" + getMaximumPoolSize(_scheduledPools)
            + " scheduler,");
    _log.info("\t... " + getPoolSize(_instantPools) + "/" + getMaximumPoolSize(_instantPools) + " instant,");
    _log.info("\t... " + getPoolSize(_longRunningPools) + "/" + getMaximumPoolSize(_longRunningPools)
            + " long running thread(s).");
}

From source file:com.l2jfree.gameserver.ThreadPoolManager.java

private ThreadPoolManager() {
    final int instantPoolSize = Math.max(1, Config.THREAD_POOL_SIZE / 3);

    _scheduledPool = new ScheduledThreadPoolExecutor(Config.THREAD_POOL_SIZE - instantPoolSize);
    _scheduledPool.setRejectedExecutionHandler(new L2RejectedExecutionHandler());
    _scheduledPool.prestartAllCoreThreads();

    _instantPool = new ThreadPoolExecutor(instantPoolSize, instantPoolSize, 0, TimeUnit.SECONDS,
            new ArrayBlockingQueue<Runnable>(100000));
    _instantPool.setRejectedExecutionHandler(new L2RejectedExecutionHandler());
    _instantPool.prestartAllCoreThreads();

    _longRunningPool = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>());
    _longRunningPool.setRejectedExecutionHandler(new L2RejectedExecutionHandler());
    _longRunningPool.prestartAllCoreThreads();

    scheduleAtFixedRate(new Runnable() {
        @Override/*  w ww .  j a v  a  2s .c o  m*/
        public void run() {
            purge();
        }
    }, 60000, 60000);

    _log.info("ThreadPoolManager: Initialized with " + _scheduledPool.getPoolSize() + " scheduler, "
            + _instantPool.getPoolSize() + " instant, " + _longRunningPool.getPoolSize()
            + " long running thread(s).");
}

From source file:org.mule.util.store.AbstractMonitoredObjectStore.java

public void initialise() throws InitialisationException {
    if (name == null) {
        name = UUID.getUUID();/*  ww  w .  jav  a  2  s .  co m*/
    }

    if (expirationInterval <= 0) {
        throw new IllegalArgumentException(CoreMessages
                .propertyHasInvalidValue("expirationInterval", new Integer(expirationInterval)).toString());
    }

    if (scheduler == null) {
        this.scheduler = new ScheduledThreadPoolExecutor(1);
        scheduler
                .setThreadFactory(new DaemonThreadFactory(name + "-Monitor", this.getClass().getClassLoader()));
        scheduler.scheduleWithFixedDelay(this, 0, expirationInterval, TimeUnit.MILLISECONDS);
    }
}