本文整理汇总了Java中java.util.concurrent.ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy方法的典型用法代码示例。如果您正苦于以下问题:Java ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy方法的具体用法?Java ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy怎么用?Java ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ScheduledThreadPoolExecutor
的用法示例。
在下文中一共展示了ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scheduler
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
@Override
protected ScheduledExecutorService scheduler() {
if (this.scheduler == null) {
synchronized (this) {
if (this.scheduler == null) {
ThreadFactory timerFactory = new ThreadFactoryBuilder()
.setNameFormat("AsyncReporter-" + id + "-timer-%d")
.setDaemon(true)
.build();
ScheduledThreadPoolExecutor timerPool = new ScheduledThreadPoolExecutor(timerThreads, timerFactory);
timerPool.setRemoveOnCancelPolicy(true);
this.scheduler = timerPool;
return timerPool;
}
}
}
return scheduler;
}
示例2: test
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
void test(String[] args) throws Throwable {
final ScheduledThreadPoolExecutor pool =
new ScheduledThreadPoolExecutor(1);
// Needed to avoid OOME
pool.setRemoveOnCancelPolicy(true);
final long moreThanYouCanChew = Runtime.getRuntime().freeMemory() / 4;
System.out.printf("moreThanYouCanChew=%d%n", moreThanYouCanChew);
Runnable noopTask = new Runnable() { public void run() {}};
for (long i = 0; i < moreThanYouCanChew; i++)
pool.schedule(noopTask, 10, TimeUnit.MINUTES).cancel(true);
pool.shutdown();
check(pool.awaitTermination(1L, TimeUnit.DAYS));
checkTerminated(pool);
equal(pool.getTaskCount(), 0L);
equal(pool.getCompletedTaskCount(), 0L);
}
示例3: ChoreService
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
* @param coreThreadPoolPrefix Prefix that will be applied to the Thread name of all threads
* spawned by this service
* @param corePoolSize The initial size to set the core pool of the ScheduledThreadPoolExecutor
* to during initialization. The default size is 1, but specifying a larger size may be
* beneficial if you know that 1 thread will not be enough.
*/
public ChoreService(final String coreThreadPoolPrefix, int corePoolSize, boolean jitter) {
this.coreThreadPoolPrefix = coreThreadPoolPrefix;
if (corePoolSize < MIN_CORE_POOL_SIZE) {
corePoolSize = MIN_CORE_POOL_SIZE;
}
final ThreadFactory threadFactory = new ChoreServiceThreadFactory(coreThreadPoolPrefix);
if (jitter) {
scheduler = new JitterScheduledThreadPoolExecutorImpl(corePoolSize, threadFactory, 0.1);
} else {
scheduler = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
}
scheduler.setRemoveOnCancelPolicy(true);
scheduledChores = new HashMap<ScheduledChore, ScheduledFuture<?>>();
choresMissingStartTime = new HashMap<ScheduledChore, Boolean>();
}
示例4: initSyncExecutor
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
private static ScheduledThreadPoolExecutor initSyncExecutor()
{
if (DatabaseDescriptor.isClientOrToolInitialized())
return null;
// Do NOT start this thread pool in client mode
ScheduledThreadPoolExecutor syncExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("read-hotness-tracker"));
// Immediately remove readMeter sync task when cancelled.
syncExecutor.setRemoveOnCancelPolicy(true);
return syncExecutor;
}
示例5: newScheduler
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
private static ListeningScheduledExecutorService newScheduler() {
final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1);
scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
scheduler.setRemoveOnCancelPolicy(true);
return MoreExecutors.listeningDecorator(scheduler);
}
示例6: initialize
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void initialize(InitializationContext ctx) throws HekateException {
guard.lockWrite();
try {
guard.becomeInitialized();
if (DEBUG) {
log.debug("Initializing...");
}
if (!channelsConfig.isEmpty()) {
nodeId = ctx.localNode().id();
HekateThreadFactory timerFactory = new HekateThreadFactory(MESSAGING_THREAD_PREFIX + "Timer");
timer = new ScheduledThreadPoolExecutor(1, timerFactory);
timer.setRemoveOnCancelPolicy(true);
channelsConfig.forEach(this::registerChannel);
cluster.addListener(this::updateTopology, ClusterEventType.JOIN, ClusterEventType.CHANGE);
}
if (DEBUG) {
log.debug("Initialized.");
}
} finally {
guard.unlockWrite();
}
}
示例7: init
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public ControllerParent<VibrationShield> init(String tag) {
scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
if(Build.VERSION.SDK_INT >= 21)
scheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true);
onStart = new Runnable() {
@Override
public void run() {
if (vibrationShieldListener != null) vibrationShieldListener.onStart();
synchronized (VibrationShield.this) {
isVibrating = true;
isPaused = false;
}
}
};
onPause = new Runnable() {
@Override
public void run() {
if (vibrationShieldListener != null) vibrationShieldListener.onPause();
synchronized (VibrationShield.this) {
isVibrating = false;
isPaused = true;
}
}
};
onStop = new Runnable() {
@Override
public void run() {
if (vibrationShieldListener != null) vibrationShieldListener.onStop();
synchronized (VibrationShield.this) {
isVibrating = false;
isPaused = false;
}
}
};
futureTasks = new Vector<>();
return super.init(tag);
}
示例8: buildDefaultTimeoutThreadPool
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
* Creates a {@link ScheduledThreadPoolExecutor} with custom name for the threads.
*
* @param name the prefix to add to the thread name in ThreadFactory.
* @return The default thread pool for request timeout and client execution timeout features.
*/
public static ScheduledThreadPoolExecutor buildDefaultTimeoutThreadPool(final String name) {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(5, getThreadFactory(name));
executor.setRemoveOnCancelPolicy(true);
executor.setKeepAliveTime(5, TimeUnit.SECONDS);
executor.allowCoreThreadTimeOut(true);
return executor;
}
示例9: initialize
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
@Override
public void initialize(InitializationContext ctx) throws HekateException {
guard.lockWrite();
try {
guard.becomeInitialized();
if (DEBUG) {
log.debug("Initializing...");
}
if (!regionsConfig.isEmpty()) {
ClusterNode node = ctx.localNode();
cluster.addListener(evt -> processTopologyChange(), ClusterEventType.JOIN, ClusterEventType.CHANGE);
scheduler = new ScheduledThreadPoolExecutor(1, new HekateThreadFactory("LockService"));
scheduler.setRemoveOnCancelPolicy(true);
MessagingChannel<LockProtocol> channel = messaging.channel(CHANNEL_NAME, LockProtocol.class);
regionsConfig.forEach(cfg -> {
if (DEBUG) {
log.debug("Registering new lock region [config={}]", cfg);
}
String name = cfg.getName().trim();
LockRegionNodeFilter regionFilter = new LockRegionNodeFilter(name);
regions.put(name, new DefaultLockRegion(name, node.id(), scheduler, channel.filter(regionFilter), retryInterval));
});
}
if (DEBUG) {
log.debug("Initialized.");
}
} finally {
guard.unlockWrite();
}
}
示例10: GenericConnectionManager
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
public GenericConnectionManager(
TransactionManager transactionManager,
TransactionSupportLevel transactionSupportLevel,
SubjectSource subjectSource,
ClassLoader classLoader,
ManagedConnectionFactory managedConnectionFactory,
String name,
String poolName,
int minIdle,
int maxPoolSize,
long connectionTimeout,
long idleTimeout,
long maxLifetime,
long aliveBypassWindow,
long houseKeepingPeriod) {
this.transactionManager = transactionManager;
this.transactionSupportLevel = transactionSupportLevel;
this.subjectSource = subjectSource;
this.classLoader = classLoader;
this.managedConnectionFactory = managedConnectionFactory;
this.name = name;
this.poolName = poolName;
this.minIdle = minIdle;
this.maxPoolSize = maxPoolSize;
this.connectionTimeout = connectionTimeout;
this.idleTimeout = idleTimeout;
this.maxLifetime = maxLifetime;
this.aliveBypassWindow = aliveBypassWindow;
this.houseKeepingPeriod = houseKeepingPeriod;
final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new UtilityElf.DefaultThreadFactory(poolName + " housekeeper", true), new ThreadPoolExecutor.DiscardPolicy());
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
executor.setRemoveOnCancelPolicy(true);
this.houseKeepingExecutorService = executor;
this.addConnectionExecutor = createThreadPoolExecutor(this.maxPoolSize, poolName + " connection adder", null, new ThreadPoolExecutor.DiscardPolicy());
this.closeConnectionExecutor = createThreadPoolExecutor(this.maxPoolSize, poolName + " connection closer", null, new ThreadPoolExecutor.CallerRunsPolicy());
this.houseKeeperTask = this.houseKeepingExecutorService.scheduleWithFixedDelay(this::houseKeep, 100L, this.houseKeepingPeriod, MILLISECONDS);
if (transactionManager != null && name != null) {
transactionManager.registerResource(new RecoverableResourceFactoryImpl(managedConnectionFactory, name));
}
}
示例11: MessagingExecutorSync
import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
public MessagingExecutorSync(ThreadFactory threadFactory, ScheduledExecutorService timer) {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, threadFactory);
executor.setRemoveOnCancelPolicy(true);
worker = new MessagingSingleThreadWorker(threadFactory, timer);
}