当前位置: 首页>>代码示例>>Java>>正文


Java ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy方法代码示例

本文整理汇总了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;
}
 
开发者ID:tramchamploo,项目名称:buffer-slayer,代码行数:19,代码来源:AsyncReporter.java

示例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);
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:BasicCancelTest.java

示例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>();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:25,代码来源:ChoreService.java

示例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;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:13,代码来源:SSTableReader.java

示例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);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:MatchRealtimeScheduler.java

示例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();
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:33,代码来源:DefaultMessagingService.java

示例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);
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:39,代码来源:VibrationShield.java

示例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;
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:15,代码来源:TimeoutThreadPoolBuilder.java

示例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();
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:43,代码来源:DefaultLockService.java

示例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));
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:46,代码来源:GenericConnectionManager.java

示例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);
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:8,代码来源:MessagingExecutorSync.java


注:本文中的java.util.concurrent.ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。