本文整理了Java中java.util.concurrent.ScheduledThreadPoolExecutor.<init>()
方法的一些代码示例,展示了ScheduledThreadPoolExecutor.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ScheduledThreadPoolExecutor.<init>()
方法的具体详情如下:
包路径:java.util.concurrent.ScheduledThreadPoolExecutor
类名称:ScheduledThreadPoolExecutor
方法名:<init>
[英]Creates a new ScheduledThreadPoolExecutor with the given core pool size.
[中]创建具有给定核心池大小的新ScheduledThreadPoolExecutor。
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new {@link ScheduledExecutorService} instance.
* <p>The default implementation creates a {@link ScheduledThreadPoolExecutor}.
* Can be overridden in subclasses to provide custom {@link ScheduledExecutorService} instances.
* @param poolSize the specified pool size
* @param threadFactory the ThreadFactory to use
* @param rejectedExecutionHandler the RejectedExecutionHandler to use
* @return a new ScheduledExecutorService instance
* @see #afterPropertiesSet()
* @see java.util.concurrent.ScheduledThreadPoolExecutor
*/
protected ScheduledExecutorService createExecutor(
int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
return new ScheduledThreadPoolExecutor(poolSize, threadFactory, rejectedExecutionHandler);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new {@link ScheduledExecutorService} instance.
* <p>The default implementation creates a {@link ScheduledThreadPoolExecutor}.
* Can be overridden in subclasses to provide custom {@link ScheduledExecutorService} instances.
* @param poolSize the specified pool size
* @param threadFactory the ThreadFactory to use
* @param rejectedExecutionHandler the RejectedExecutionHandler to use
* @return a new ScheduledExecutorService instance
* @see #afterPropertiesSet()
* @see java.util.concurrent.ScheduledThreadPoolExecutor
*/
protected ScheduledExecutorService createExecutor(
int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
return new ScheduledThreadPoolExecutor(poolSize, threadFactory, rejectedExecutionHandler);
}
代码示例来源:origin: springside/springside4
public ScheduledThreadPoolExecutor build() {
threadFactory = createThreadFactory(threadFactory, threadNamePrefix, Boolean.TRUE);
return new ScheduledThreadPoolExecutor(poolSize, threadFactory);
}
}
代码示例来源:origin: org.springframework/spring-context
/**
* Create a new {@link ScheduledExecutorService} instance.
* <p>The default implementation creates a {@link ScheduledThreadPoolExecutor}.
* Can be overridden in subclasses to provide custom {@link ScheduledExecutorService} instances.
* @param poolSize the specified pool size
* @param threadFactory the ThreadFactory to use
* @param rejectedExecutionHandler the RejectedExecutionHandler to use
* @return a new ScheduledExecutorService instance
* @see #afterPropertiesSet()
* @see java.util.concurrent.ScheduledThreadPoolExecutor
*/
protected ScheduledExecutorService createExecutor(
int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
return new ScheduledThreadPoolExecutor(poolSize, threadFactory, rejectedExecutionHandler);
}
代码示例来源:origin: org.springframework/spring-context
/**
* Create a new {@link ScheduledExecutorService} instance.
* <p>The default implementation creates a {@link ScheduledThreadPoolExecutor}.
* Can be overridden in subclasses to provide custom {@link ScheduledExecutorService} instances.
* @param poolSize the specified pool size
* @param threadFactory the ThreadFactory to use
* @param rejectedExecutionHandler the RejectedExecutionHandler to use
* @return a new ScheduledExecutorService instance
* @see #afterPropertiesSet()
* @see java.util.concurrent.ScheduledThreadPoolExecutor
*/
protected ScheduledExecutorService createExecutor(
int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
return new ScheduledThreadPoolExecutor(poolSize, threadFactory, rejectedExecutionHandler);
}
代码示例来源:origin: alibaba/druid
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);
}
代码示例来源:origin: koral--/android-gif-drawable
/**
* Sets thread pool size for rendering tasks.
* Warning: custom executor set by {@link #taskExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)}
* will be overwritten after setting pool size
*
* @param threadPoolSize size of the pool
* @return this builder instance, to chain calls
*/
public T threadPoolSize(int threadPoolSize) {
mExecutor = new ScheduledThreadPoolExecutor(threadPoolSize);
return self();
}
代码示例来源:origin: square/okhttp
public void initReaderAndWriter(String name, Streams streams) throws IOException {
synchronized (this) {
this.streams = streams;
this.writer = new WebSocketWriter(streams.client, streams.sink, random);
this.executor = new ScheduledThreadPoolExecutor(1, Util.threadFactory(name, false));
if (pingIntervalMillis != 0) {
executor.scheduleAtFixedRate(
new PingRunnable(), pingIntervalMillis, pingIntervalMillis, MILLISECONDS);
}
if (!messageAndCloseQueue.isEmpty()) {
runWriter(); // Send messages that were enqueued before we were connected.
}
}
reader = new WebSocketReader(streams.client, streams.source, this);
}
代码示例来源:origin: apache/storm
@Override
public void activate() {
LOG.info("Start checking heartbeat...");
// prevent timer to check heartbeat based on last thing before activate
setHeartbeat();
if (heartBeatExecutorService.isShutdown()) {
//In case deactivate was called before
heartBeatExecutorService = MoreExecutors.getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(1));
}
heartBeatExecutorService.scheduleAtFixedRate(new SpoutHeartbeatTimerTask(this), 1, 1, TimeUnit.SECONDS);
this.sendSyncCommand("activate", "");
}
代码示例来源:origin: alibaba/jstorm
public void open(Map stormConf, TopologyContext context, SpoutOutputCollector collector) {
_collector = collector;
_context = context;
workerTimeoutMills = 1000 * RT.intCast(stormConf.get(Config.SUPERVISOR_WORKER_TIMEOUT_SECS));
_process = new ShellProcess(_command);
Number subPid = _process.launch(stormConf, context);
LOG.info("Launched subprocess with pid " + subPid);
heartBeatExecutorService = MoreExecutors.getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(1));
}
代码示例来源:origin: dropwizard/dropwizard
public ScheduledExecutorService build() {
final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(this.poolSize, this.threadFactory, this.handler);
executor.setRemoveOnCancelPolicy(this.removeOnCancel);
this.environment.manage(new ExecutorServiceManager(executor, this.shutdownTime, this.nameFormat));
return executor;
}
}
代码示例来源:origin: prestodb/presto
public void initReaderAndWriter(
String name, long pingIntervalMillis, Streams streams) throws IOException {
synchronized (this) {
this.streams = streams;
this.writer = new WebSocketWriter(streams.client, streams.sink, random);
this.executor = new ScheduledThreadPoolExecutor(1, Util.threadFactory(name, false));
if (pingIntervalMillis != 0) {
executor.scheduleAtFixedRate(
new PingRunnable(), pingIntervalMillis, pingIntervalMillis, MILLISECONDS);
}
if (!messageAndCloseQueue.isEmpty()) {
runWriter(); // Send messages that were enqueued before we were connected.
}
}
reader = new WebSocketReader(streams.client, streams.source, this);
}
代码示例来源:origin: google/guava
public void testListeningDecorator_scheduleFailure() throws Exception {
ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1);
ListeningScheduledExecutorService service = listeningDecorator(delegate);
RuntimeException ex = new RuntimeException();
ListenableFuture<?> future =
service.schedule(new ThrowingRunnable(0, ex), 1, TimeUnit.MILLISECONDS);
assertExecutionException(future, ex);
assertEquals(0, delegate.getQueue().size());
}
代码示例来源:origin: google/guava
public void testGetExitingScheduledExecutorService_executorSetToUseDaemonThreads() {
TestApplication application = new TestApplication();
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
assertNotNull(application.getExitingScheduledExecutorService(executor));
assertTrue(executor.getThreadFactory().newThread(EMPTY_RUNNABLE).isDaemon());
}
代码示例来源:origin: square/okhttp
writerExecutor = new ScheduledThreadPoolExecutor(1,
Util.threadFactory(Util.format("OkHttp %s Writer", connectionName), false));
if (builder.pingIntervalMillis != 0) {
代码示例来源:origin: lets-blade/blade
public static void main(String[] args) throws ParseException {
ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(2);
System.out.println("Hello World1");
scheduledThreadPoolExecutor.schedule(() -> {
System.out.println("Hello World2");
}, 5000, TimeUnit.MILLISECONDS);
scheduledThreadPoolExecutor.shutdown();
CronExecutorService cronExecutorService = new CronThreadPoolExecutor(2, null);
cronExecutorService.submit(new Task("task1", new CronExpression("* * * * ?"), 0L));
}
代码示例来源:origin: apache/rocketmq
public void start() throws MQClientException {
final String group = this.defaultMQPullConsumer.getConsumerGroup();
this.scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(
this.pullThreadNums,
new ThreadFactoryImpl("PullMsgThread-" + group)
);
this.defaultMQPullConsumer.setMessageQueueListener(this.messageQueueListener);
this.defaultMQPullConsumer.start();
log.info("MQPullConsumerScheduleService start OK, {} {}",
this.defaultMQPullConsumer.getConsumerGroup(), this.callbackTable);
}
代码示例来源:origin: google/guava
public void testListeningDecorator_schedulePeriodic() throws Exception {
ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1);
ListeningScheduledExecutorService service = listeningDecorator(delegate);
RuntimeException ex = new RuntimeException();
ListenableFuture<?> future;
ThrowingRunnable runnable = new ThrowingRunnable(5, ex);
future = service.scheduleAtFixedRate(runnable, 1, 1, TimeUnit.MILLISECONDS);
assertExecutionException(future, ex);
assertEquals(5, runnable.count);
assertEquals(0, delegate.getQueue().size());
runnable = new ThrowingRunnable(5, ex);
future = service.scheduleWithFixedDelay(runnable, 1, 1, TimeUnit.MILLISECONDS);
assertExecutionException(future, ex);
assertEquals(5, runnable.count);
assertEquals(0, delegate.getQueue().size());
}
代码示例来源:origin: google/guava
public void testListeningDecorator_cancelled() throws Exception {
ScheduledThreadPoolExecutor delegate = new ScheduledThreadPoolExecutor(1);
BlockingQueue<?> delegateQueue = delegate.getQueue();
ListeningScheduledExecutorService service = listeningDecorator(delegate);
ListenableFuture<?> future;
ScheduledFuture<?> delegateFuture;
Runnable runnable =
new Runnable() {
@Override
public void run() {}
};
future = service.schedule(runnable, 5, TimeUnit.MINUTES);
future.cancel(true);
assertTrue(future.isCancelled());
delegateFuture = (ScheduledFuture<?>) delegateQueue.element();
assertTrue(delegateFuture.isCancelled());
delegateQueue.clear();
future = service.scheduleAtFixedRate(runnable, 5, 5, TimeUnit.MINUTES);
future.cancel(true);
assertTrue(future.isCancelled());
delegateFuture = (ScheduledFuture<?>) delegateQueue.element();
assertTrue(delegateFuture.isCancelled());
delegateQueue.clear();
future = service.scheduleWithFixedDelay(runnable, 5, 5, TimeUnit.MINUTES);
future.cancel(true);
assertTrue(future.isCancelled());
delegateFuture = (ScheduledFuture<?>) delegateQueue.element();
assertTrue(delegateFuture.isCancelled());
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testStopWithNoFileUsingExecutor() throws Exception {
final File file = new File(getTestDirectory(),"nosuchfile");
assertFalse("nosuchfile should not exist", file.exists());
final TestTailerListener listener = new TestTailerListener();
final int delay = 100;
final int idle = 50; // allow time for thread to work
tailer = new Tailer(file, listener, delay, false);
final Executor exec = new ScheduledThreadPoolExecutor(1);
exec.execute(tailer);
TestUtils.sleep(idle);
tailer.stop();
TestUtils.sleep(delay+idle);
assertNull("Should not generate Exception", listener.exception);
assertEquals("Expected init to be called", 1 , listener.initialised);
assertTrue("fileNotFound should be called", listener.notFound > 0);
assertEquals("fileRotated should be not be called", 0 , listener.rotated);
assertEquals("end of file never reached", 0, listener.reachedEndOfFile);
}
内容来源于网络,如有侵权,请联系作者删除!