Java Code Examples for java.util.concurrent.ScheduledThreadPoolExecutor#setMaximumPoolSize()

The following examples show how to use java.util.concurrent.ScheduledThreadPoolExecutor#setMaximumPoolSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimerServiceImpl.java    From AlgoTrader with GNU General Public License v2.0 6 votes vote down vote up
private void getScheduledThreadPoolExecutorDaemonThread() {
	timer = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
		// set new thread as daemon thread and name appropriately
		public Thread newThread(Runnable r) {
               String uri = engineURI;
               if (engineURI == null)
               {
                   uri = "default";
               }
               Thread t = new Thread(r, "com.espertech.esper.Timer-" + uri + "-" + id);
			//t.setDaemon(true);
			return t;
		}
	});
	timer.setMaximumPoolSize(timer.getCorePoolSize());
}
 
Example 2
Source File: Utilities.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("SameParameterValue")
public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String name,
                                                                         int corePoolSize,
                                                                         int maximumPoolSize,
                                                                         long keepAliveTimeInSec) {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder()
            .setNameFormat(name)
            .setDaemon(true)
            .setPriority(Thread.MIN_PRIORITY)
            .build();
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
    executor.setKeepAliveTime(keepAliveTimeInSec, TimeUnit.SECONDS);
    executor.allowCoreThreadTimeOut(true);
    executor.setMaximumPoolSize(maximumPoolSize);
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    executor.setRejectedExecutionHandler((r, e) -> log.debug("RejectedExecutionHandler called"));
    return executor;
}
 
Example 3
Source File: MockedRemoteFunctionClient.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
public MockedRemoteFunctionClient(Connector connectorConfig) {
    super(connectorConfig);
    threadPool = new ScheduledThreadPoolExecutor(connectorConfig.connectionSettings.maxConnections, Executors.defaultThreadFactory(), (r, executor) -> {
        MockedRequest mr = (MockedRequest) r;
        mr.callback.handle(Future.failedFuture(new Exception("Connector is too busy.")));
    });
    threadPool.setMaximumPoolSize(connectorConfig.connectionSettings.maxConnections);
}
 
Example 4
Source File: Ideas_2008_08_06.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@ExpectWarning("GC,Dm")
public static void main(String args[]) {
    Ideas_2008_08_06<String> i = new Ideas_2008_08_06<String>();
    System.out.println(i.contains(5));
    ScheduledThreadPoolExecutor e = new ScheduledThreadPoolExecutor(0);
    e.setMaximumPoolSize(10);
}
 
Example 5
Source File: ParallelScheduler.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates the default {@link ScheduledExecutorService} for the ParallelScheduler
 * ({@code Executors.newScheduledThreadPoolExecutor} with core and max pool size of 1).
 */
@Override
public ScheduledExecutorService get() {
    ScheduledThreadPoolExecutor poolExecutor = new ScheduledThreadPoolExecutor(1, factory);
    poolExecutor.setMaximumPoolSize(1);
    poolExecutor.setRemoveOnCancelPolicy(true);
    return poolExecutor;
}
 
Example 6
Source File: SingleScheduler.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates the default {@link ScheduledExecutorService} for the SingleScheduler
 * ({@code Executors.newScheduledThreadPoolExecutor} with core and max pool size of 1).
 */
@Override
public ScheduledExecutorService get() {
	ScheduledThreadPoolExecutor e = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, this.factory);
	e.setRemoveOnCancelPolicy(true);
	e.setMaximumPoolSize(1);
	return e;
}
 
Example 7
Source File: ElasticScheduler.java    From reactor-core with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates the default {@link ScheduledExecutorService} for the ElasticScheduler
 * ({@code Executors.newScheduledThreadPoolExecutor} with core and max pool size of 1).
 */
public ScheduledExecutorService createUndecoratedService() {
	ScheduledThreadPoolExecutor poolExecutor = new ScheduledThreadPoolExecutor(1, factory);
	poolExecutor.setMaximumPoolSize(1);
	poolExecutor.setRemoveOnCancelPolicy(true);
	return poolExecutor;
}
 
Example 8
Source File: CustomSchedulingConfiguration.java    From booties with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public ScheduledExecutorService scheduledExecutorService() {
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(properties.getCorePoolSize());

    executor.setMaximumPoolSize(properties.getMaxPoolSize());

    executor.setThreadFactory(new CustomizableThreadFactory(properties.getThreadNamePrefix()));

    executor.setRejectedExecutionHandler(getConfiguredRejectedExecutionHandler());
    return executor;
}
 
Example 9
Source File: LifecycleSupervisor.java    From mt-flume with Apache License 2.0 5 votes vote down vote up
public LifecycleSupervisor() {
  lifecycleState = LifecycleState.IDLE;
  supervisedProcesses = new HashMap<LifecycleAware, Supervisoree>();
  monitorFutures = new HashMap<LifecycleAware, ScheduledFuture<?>>();
  monitorService = new ScheduledThreadPoolExecutor(10,
      new ThreadFactoryBuilder().setNameFormat(
          "lifecycleSupervisor-" + Thread.currentThread().getId() + "-%d")
          .build());
  monitorService.setMaximumPoolSize(20);
  monitorService.setKeepAliveTime(30, TimeUnit.SECONDS);
  purger = new Purger();
  needToPurge = false;
}
 
Example 10
Source File: ExecutorUtils.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
public static ScheduledThreadPoolExecutor createSingleThreadSchedulingDeamonPool(final String threadPurpose) {
    final ThreadFactory daemonThreadFactory = new NamedThreadFactory(ThreadUtils.addElasticApmThreadPrefix(threadPurpose));
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, daemonThreadFactory);
    executor.setMaximumPoolSize(1);
    return executor;
}