當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。