本文整理汇总了Java中java.util.concurrent.Executors.newScheduledThreadPool方法的典型用法代码示例。如果您正苦于以下问题:Java Executors.newScheduledThreadPool方法的具体用法?Java Executors.newScheduledThreadPool怎么用?Java Executors.newScheduledThreadPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.Executors
的用法示例。
在下文中一共展示了Executors.newScheduledThreadPool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ZKNodeWatcher
import java.util.concurrent.Executors; //导入方法依赖的package包/类
/**
*
* @param zkMonitorListener a {@link ZKMonitorCallback} instance
* @param zkNodeAddress Zookeeper server address
* @param zkNodePollingDelay Amount of time in ms to poll zookeeper node
* @param zkNodePollingInitialDelay Amount of initial time in ms before starting poll
*/
public ZKNodeWatcher(final ZKMonitorCallback zkMonitorListener,
final InetSocketAddress zkNodeAddress,
final int zkNodePollingDelay,
final int zkNodePollingInitialDelay) {
validateArguments(zkMonitorListener,
zkNodeAddress,
zkNodePollingDelay,
zkNodePollingInitialDelay);
this.zkNodeAddress = zkNodeAddress;
this.zkMonitorListener = zkMonitorListener;
this.zkNodePollingDelay = zkNodePollingDelay;
this.zkNodePollingInitialDelay = zkNodePollingInitialDelay;
this.executor = Executors.newScheduledThreadPool(1);
}
示例2: fixedDelay
import java.util.concurrent.Executors; //导入方法依赖的package包/类
private static void fixedDelay() {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
Runnable task = () -> {
try {
System.out.println("Scheduling: " + System.nanoTime());
TimeUnit.SECONDS.sleep(2);
System.out.println("Ready: " + System.nanoTime());
}
catch (InterruptedException e) {
System.err.println("task interrupted");
}
};
executor.scheduleWithFixedDelay(task, 0, 4, TimeUnit.SECONDS);
}
示例3: postConstruct
import java.util.concurrent.Executors; //导入方法依赖的package包/类
@PostConstruct
private void postConstruct() {
allEnvs = portalConfig.portalSupportedEnvs();
for (Env env : allEnvs) {
envStatusMark.put(env, true);
}
ScheduledExecutorService
healthCheckService =
Executors.newScheduledThreadPool(1, ApolloThreadFactory.create("EnvHealthChecker", false));
healthCheckService
.scheduleWithFixedDelay(new HealthCheckTask(applicationContext), 1000, HEALTH_CHECK_INTERVAL,
TimeUnit.MILLISECONDS);
}
示例4: initCollectionTimer
import java.util.concurrent.Executors; //导入方法依赖的package包/类
/**
*
*/
private void initCollectionTimer() {
statScheduler = Executors.newScheduledThreadPool(1);
statScheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
lock.lock();
try {
//抓取kafka消费组信息
fetchConsumerGroupFromKafkaAndZK();
fetchProducerStatFromZK();
} finally {
lock.unlock();
}
}
}, 1, 5, TimeUnit.SECONDS);
}
示例5: main
import java.util.concurrent.Executors; //导入方法依赖的package包/类
public static void main(String[] args) {
final LoadMonitor monitor = new LoadMonitor(null);
final ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool(1);
final ScheduledFuture<?> monitorTask =
monitor.startMonitoring(scheduler);
final ScheduledFuture<?> printTask =
monitor.printMonitoring(scheduler);
// Run the tasks for 2 minutes
scheduler.schedule(
new Runnable() {
public void run() {
monitorTask.cancel(true);
printTask.cancel(true);
}
}, 5*60, TimeUnit.SECONDS);
}
示例6: CachedWorkerPool
import java.util.concurrent.Executors; //导入方法依赖的package包/类
CachedWorkerPool(long keepAliveTime, TimeUnit unit) {
this.keepAliveTime = unit != null ? unit.toNanos(keepAliveTime) : 0;
this.expiringWorkerQueue = new ConcurrentLinkedQueue();
this.allWorkers = new CompositeSubscription();
ScheduledExecutorService evictor = null;
Future<?> task = null;
if (unit != null) {
evictor = Executors.newScheduledThreadPool(1, CachedThreadScheduler.EVICTOR_THREAD_FACTORY);
NewThreadWorker.tryEnableCancelPolicy(evictor);
task = evictor.scheduleWithFixedDelay(new Runnable() {
public void run() {
CachedWorkerPool.this.evictExpiredWorkers();
}
}, this.keepAliveTime, this.keepAliveTime, TimeUnit.NANOSECONDS);
}
this.evictorService = evictor;
this.evictorTask = task;
}
示例7: MemStoreChunkPool
import java.util.concurrent.Executors; //导入方法依赖的package包/类
MemStoreChunkPool(Configuration conf, int chunkSize, int maxCount,
int initialCount) {
this.maxCount = maxCount;
this.chunkSize = chunkSize;
this.reclaimedChunks = new LinkedBlockingQueue<Chunk>();
for (int i = 0; i < initialCount; i++) {
Chunk chunk = new Chunk(chunkSize);
chunk.init();
reclaimedChunks.add(chunk);
}
final String n = Thread.currentThread().getName();
scheduleThreadPool = Executors.newScheduledThreadPool(1,
new ThreadFactoryBuilder().setNameFormat(n+"-MemStoreChunkPool Statistics")
.setDaemon(true).build());
this.scheduleThreadPool.scheduleAtFixedRate(new StatisticsThread(this),
statThreadPeriod, statThreadPeriod, TimeUnit.SECONDS);
}
示例8: demo
import java.util.concurrent.Executors; //导入方法依赖的package包/类
static void demo() {
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5);
// 延迟3秒执行
scheduledThreadPool.schedule(new Runnable() {
public void run() {
System.out.println("delay 3 seconds");
}
}, 3, TimeUnit.SECONDS);
// 表示延迟1秒后每3秒执行一次
scheduledThreadPool.scheduleAtFixedRate(new Runnable() {
public void run() {
System.out.println("delay 1 seconds, and excute every 3 seconds");
}
}, 1, 3, TimeUnit.SECONDS);
}
示例9: test2
import java.util.concurrent.Executors; //导入方法依赖的package包/类
private static void test2() {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
Runnable task = () -> System.out.println("Scheduling: " + System.nanoTime());
int initialDelay = 0;
int period = 1;
executor.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
}
示例10: initialize
import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Override
public void initialize() {
api.registerforChangeEvents(this);
ScheduledExecutorService executerPool = Executors.newScheduledThreadPool(1);
executerPool.schedule(new InitializationRunnable(), 3, TimeUnit.SECONDS);
updateStatus(ThingStatus.ONLINE);
super.initialize();
}
示例11: scheduleWithFixedDelay
import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay,
long delay, TimeUnit unit) {
if (ses == null)
ses = Executors.newScheduledThreadPool(1);
try {
return ses.scheduleWithFixedDelay(command, initialDelay, delay, unit);
} catch (Exception e) {
return new MockFuture<Object>(new ExecutionException(e));
}
}
示例12: IOSScheduledExecutorPool
import java.util.concurrent.Executors; //导入方法依赖的package包/类
private IOSScheduledExecutorPool() {
executorService = Executors.newScheduledThreadPool(1, THREAD_FACTORY);
}
示例13: initScheduleSync
import java.util.concurrent.Executors; //导入方法依赖的package包/类
public void initScheduleSync()
{
// every 15 minutes create a thread to check for schedules to sync
ScheduledExecutorService syncScheduler = Executors.newScheduledThreadPool(1);
syncScheduler.scheduleAtFixedRate( new ScheduleSyncer(), 60*15, 60*15, TimeUnit.SECONDS );
}
示例14: ScheduledNotifier
import java.util.concurrent.Executors; //导入方法依赖的package包/类
private ScheduledNotifier() {
_pool = Executors.newScheduledThreadPool(1);
init();
}
示例15: init
import java.util.concurrent.Executors; //导入方法依赖的package包/类
public void init() {
executor = Executors.newScheduledThreadPool(1);
future = executor.scheduleAtFixedRate(new TcpHeartBeat(this), keepAliveSeconds, keepAliveSeconds,
TimeUnit.SECONDS);
connect();
}