當前位置: 首頁>>代碼示例>>Java>>正文


Java ThreadPoolExecutor.allowCoreThreadTimeOut方法代碼示例

本文整理匯總了Java中java.util.concurrent.ThreadPoolExecutor.allowCoreThreadTimeOut方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadPoolExecutor.allowCoreThreadTimeOut方法的具體用法?Java ThreadPoolExecutor.allowCoreThreadTimeOut怎麽用?Java ThreadPoolExecutor.allowCoreThreadTimeOut使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.allowCoreThreadTimeOut方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDefaultExecutor

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@InterfaceAudience.Private
public static ThreadPoolExecutor getDefaultExecutor(Configuration conf) {
  int maxThreads = conf.getInt("hbase.htable.threads.max", Integer.MAX_VALUE);
  if (maxThreads == 0) {
    maxThreads = 1; // is there a better default?
  }
  long keepAliveTime = conf.getLong("hbase.htable.threads.keepalivetime", 60);

  // Using the "direct handoff" approach, new threads will only be created
  // if it is necessary and will grow unbounded. This could be bad but in HCM
  // we only create as many Runnables as there are region servers. It means
  // it also scales when new region servers are added.
  ThreadPoolExecutor pool = new ThreadPoolExecutor(1, maxThreads, keepAliveTime, TimeUnit.SECONDS,
      new SynchronousQueue<Runnable>(), Threads.newDaemonThreadFactory("htable"));
  pool.allowCoreThreadTimeOut(true);
  return pool;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:18,代碼來源:HTable.java

示例2: AsyncDiskService

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * Create a AsyncDiskServices with a set of volumes (specified by their
 * root directories).
 * 
 * The AsyncDiskServices uses one ThreadPool per volume to do the async
 * disk operations.
 * 
 * @param volumes The roots of the file system volumes.
 */
public AsyncDiskService(String[] volumes) {
  
  threadFactory = new ThreadFactory() {
    @Override
    public Thread newThread(Runnable r) {
      return new Thread(threadGroup, r);
    }
  };
  
  // Create one ThreadPool per volume
  for (int v = 0 ; v < volumes.length; v++) {
    ThreadPoolExecutor executor = new ThreadPoolExecutor(
        CORE_THREADS_PER_VOLUME, MAXIMUM_THREADS_PER_VOLUME, 
        THREADS_KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, 
        new LinkedBlockingQueue<Runnable>(), threadFactory);

    // This can reduce the number of running threads
    executor.allowCoreThreadTimeOut(true);
    executors.put(volumes[v], executor);
  }
  
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:32,代碼來源:AsyncDiskService.java

示例3: createIOPoolExecutor

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private ThreadPoolExecutor createIOPoolExecutor(){
	//IO線程工廠類
	ThreadFactory threadFactory = new ThreadFactory() {
		@Override
		public Thread newThread(@NonNull Runnable runnable) {
			Thread thread = new Thread(runnable);
			thread.setName("dunit-io");
			return thread;
		}
	};

	//創建一個任務拒絕策略
	//直接忽略新進的任務
	RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.DiscardPolicy();
	//創建一個最大線程數為3的線程池
	ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(1, 3, 3, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(10),threadFactory,rejectedExecutionHandler);
	//當核心線程空閑時,允許殺死核心線程
	poolExecutor.allowCoreThreadTimeOut(true);
	return poolExecutor;
}
 
開發者ID:tik5213,項目名稱:DUnit,代碼行數:21,代碼來源:DUnitThreadManager.java

示例4: initializeCacheExecutor

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
protected ThreadPoolExecutor initializeCacheExecutor(File parent) {
  if (storageType.isTransient()) {
    return null;
  }
  if (dataset.datanode == null) {
    // FsVolumeImpl is used in test.
    return null;
  }

  final int maxNumThreads = dataset.datanode.getConf().getInt(
      DFSConfigKeys.DFS_DATANODE_FSDATASETCACHE_MAX_THREADS_PER_VOLUME_KEY,
      DFSConfigKeys.DFS_DATANODE_FSDATASETCACHE_MAX_THREADS_PER_VOLUME_DEFAULT);

  ThreadFactory workerFactory = new ThreadFactoryBuilder()
      .setDaemon(true)
      .setNameFormat("FsVolumeImplWorker-" + parent.toString() + "-%d")
      .build();
  ThreadPoolExecutor executor = new ThreadPoolExecutor(
      1, maxNumThreads,
      60, TimeUnit.SECONDS,
      new LinkedBlockingQueue<Runnable>(),
      workerFactory);
  executor.allowCoreThreadTimeOut(true);
  return executor;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:FsVolumeImpl.java

示例5: getDefaultExecutorService

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * Returns a new instance of a default ExecutorService.<p>
 *
 * The default executor service is a thread-limited pool
 * where the number of threads is one less than the number
 * of processors set with {@link #setNumberOfProcessors(int)}.
 *
 * @return A new instance of a default ExecutorService.
 *
 * @since 1.3
 */

public static ExecutorService getDefaultExecutorService()
{
    // Executor service with all daemon threads, to avoid clean-up
    ThreadFactory threadFactory = new ThreadFactory()
    {
        public Thread newThread(Runnable runnable)
        {
            Thread thread = this.defaultThreadFactory.newThread(runnable);
            thread.setDaemon(true);

            return thread;
        }

        private ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory();
    };

    int numberOfThreads = Math.max(1, getContext().getNumberOfProcessors() - 1);
    ThreadPoolExecutor executorService = new ThreadPoolExecutor(numberOfThreads, numberOfThreads, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory);
    executorService.allowCoreThreadTimeOut(true);

    return executorService;
}
 
開發者ID:mtommila,項目名稱:apfloat,代碼行數:35,代碼來源:ApfloatContext.java

示例6: buildDownloadExecutor

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private static ExecutorService buildDownloadExecutor() {
    final int maxConcurrent = 5;

    // Create a bounded thread pool for executing downloads; it creates
    // threads as needed (up to maximum) and reclaims them when finished.
    final ThreadPoolExecutor executor = new ThreadPoolExecutor(
            maxConcurrent, maxConcurrent, 10, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>()) {
        @Override
        protected void afterExecute(Runnable r, Throwable t) {
            super.afterExecute(r, t);

            if (t == null && r instanceof Future<?>) {
                try {
                    ((Future<?>) r).get();
                } catch (CancellationException ce) {
                    t = ce;
                } catch (ExecutionException ee) {
                    t = ee.getCause();
                } catch (InterruptedException ie) {
                    Thread.currentThread().interrupt();
                }
            }

            if (t != null) {
                Log.w(TAG, "Uncaught exception", t);
            }
        }
    };
    executor.allowCoreThreadTimeOut(true);
    return executor;
}
 
開發者ID:redleaf2002,項目名稱:downloadmanager,代碼行數:33,代碼來源:DownloadService.java

示例7: initInternal

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
protected void initInternal() throws LifecycleException {
	BlockingQueue<Runnable> startStopQueue = new LinkedBlockingQueue<Runnable>();
	startStopExecutor = new ThreadPoolExecutor(getStartStopThreadsInternal(), getStartStopThreadsInternal(), 10,
			TimeUnit.SECONDS, startStopQueue, new StartStopThreadFactory(getName() + "-startStop-"));
	startStopExecutor.allowCoreThreadTimeOut(true);
	super.initInternal();
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:9,代碼來源:ContainerBase.java

示例8: createAstSerializerExecutorService

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * Creates the AST serializer executor service used for in-memory serialization of split functions' ASTs.
 * It is created with an unbounded queue (so it can queue any number of pending tasks). Its core and max
 * threads is the same, but they are all allowed to time out so when there's no work, they can all go
 * away. The threads will be daemons, and they will time out if idle for a minute. Their priority is also
 * slightly lower than normal priority as we'd prefer the CPU to keep running the program; serializing
 * split function is a memory conservation measure (it allows us to release the AST), it can wait a bit.
 * @return an executor service with above described characteristics.
 */
private static ExecutorService createAstSerializerExecutorService() {
    final int threads = Math.max(1, Options.getIntProperty("nashorn.serialize.threads", Runtime.getRuntime().availableProcessors() / 2));
    final ThreadPoolExecutor service = new ThreadPoolExecutor(threads, threads, 1, TimeUnit.MINUTES, new LinkedBlockingDeque<>(),
        (r) -> {
            final Thread t = new Thread(r, "Nashorn AST Serializer");
            t.setDaemon(true);
            t.setPriority(Thread.NORM_PRIORITY - 1);
            return t;
        });
    service.allowCoreThreadTimeOut(true);
    return service;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:RecompilableScriptFunctionData.java

示例9: initInternal

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
protected void initInternal() throws LifecycleException {
    BlockingQueue<Runnable> startStopQueue =
        new LinkedBlockingQueue<Runnable>();
    startStopExecutor = new ThreadPoolExecutor(
            getStartStopThreadsInternal(),
            getStartStopThreadsInternal(), 10, TimeUnit.SECONDS,
            startStopQueue,
            new StartStopThreadFactory(getName() + "-startStop-"));
    startStopExecutor.allowCoreThreadTimeOut(true);
    super.initInternal();
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:13,代碼來源:ContainerBase.java

示例10: test

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
void test(String[] args) throws Throwable {
    final int threadCount = 10;
    final int timeoutMillis = 30;
    BlockingQueue<Runnable> q = new ArrayBlockingQueue<>(2*threadCount);
    ThreadPoolExecutor tpe
        = new ThreadPoolExecutor(threadCount, threadCount,
                                 timeoutMillis, TimeUnit.MILLISECONDS,
                                 q, new IdentifiableThreadFactory());
    equal(tpe.getCorePoolSize(), threadCount);
    check(! tpe.allowsCoreThreadTimeOut());
    tpe.allowCoreThreadTimeOut(true);
    check(tpe.allowsCoreThreadTimeOut());
    equal(countExecutorThreads(), 0);
    long startTime = System.nanoTime();
    for (int i = 0; i < threadCount; i++) {
        tpe.submit(() -> {});
        int count = countExecutorThreads();
        if (millisElapsedSince(startTime) < timeoutMillis)
            equal(count, i + 1);
    }
    while (countExecutorThreads() > 0 &&
           millisElapsedSince(startTime) < LONG_DELAY_MS)
        Thread.yield();
    equal(countExecutorThreads(), 0);
    check(millisElapsedSince(startTime) >= timeoutMillis);
    tpe.shutdown();
    check(tpe.allowsCoreThreadTimeOut());
    check(tpe.awaitTermination(LONG_DELAY_MS, MILLISECONDS));

    System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
    if (failed > 0) throw new Exception("Some tests failed");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:CoreThreadTimeOut.java

示例11: newDynamicSingleThreadedExecutor

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public static ExecutorService newDynamicSingleThreadedExecutor() {
  ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS,
                                                       new LinkedBlockingQueue<Runnable>());
  executor.allowCoreThreadTimeOut(true);

  return executor;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:8,代碼來源:ThreadUtil.java

示例12: initializeExecutor

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
protected ExecutorService initializeExecutor(
		ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

	BlockingQueue<Runnable> queue = createQueue(this.queueCapacity);
	ThreadPoolExecutor executor  = new ThreadPoolExecutor(
			this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS,
			queue, threadFactory, rejectedExecutionHandler);
	if (this.allowCoreThreadTimeOut) {
		executor.allowCoreThreadTimeOut(true);
	}

	this.threadPoolExecutor = executor;
	return executor;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:ThreadPoolTaskExecutor.java

示例13: FreeMarkerService

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private FreeMarkerService(Builder bulder) {
     maxOutputLength = bulder.getMaxOutputLength();
     maxThreads = bulder.getMaxThreads();
     maxQueueLength = bulder.getMaxQueueLength();
     maxTemplateExecutionTime = bulder.getMaxTemplateExecutionTime();

     int actualMaxQueueLength = maxQueueLength != null
             ? maxQueueLength
             : Math.max(
                     MIN_DEFAULT_MAX_QUEUE_LENGTH,
                     (int) (MAX_DEFAULT_MAX_QUEUE_LENGTH_MILLISECONDS / maxTemplateExecutionTime));
     ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
             maxThreads, maxThreads,
             THREAD_KEEP_ALIVE_TIME, TimeUnit.MILLISECONDS,
             new BlockingArrayQueue<Runnable>(actualMaxQueueLength));
     threadPoolExecutor.allowCoreThreadTimeOut(true);
     templateExecutor = threadPoolExecutor;

     freeMarkerConfig = new Configuration(Configuration.getVersion());
     freeMarkerConfig.setNewBuiltinClassResolver(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER);
     freeMarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
     freeMarkerConfig.setLogTemplateExceptions(false);
     freeMarkerConfig.setAttemptExceptionReporter(new AttemptExceptionReporter() {
@Override
public void report(TemplateException te, Environment env) {
	// Suppress it
}
     });
     freeMarkerConfig.setLocale(AllowedSettingValuesMaps.DEFAULT_LOCALE);
     freeMarkerConfig.setTimeZone(AllowedSettingValuesMaps.DEFAULT_TIME_ZONE);
     freeMarkerConfig.setOutputFormat(AllowedSettingValuesMaps.DEFAULT_OUTPUT_FORMAT);
     freeMarkerConfig.setOutputEncoding("UTF-8");
 }
 
開發者ID:apache,項目名稱:incubator-freemarker-online-tester,代碼行數:34,代碼來源:FreeMarkerService.java

示例14: init

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public void init(Context context, @NonNull DownloadConfiguration config) {
    if (this.mConfig != null) {
        L.w("DownloadManger has already been initialized before");
    } else if (config.getThreadNum() > config.getMaxThreadNum()) {
        throw new IllegalArgumentException("thread num must < max thread num");
    } else {
        this.mConfig = config;
        this.mDBManager = DataBaseManager.getInstance(context);
        ThreadPoolExecutor executor = new ThreadPoolExecutor(this.mConfig.getMaxThreadNum(), this.mConfig.getMaxThreadNum(), 60, TimeUnit.SECONDS, new LinkedBlockingQueue());
        executor.allowCoreThreadTimeOut(true);
        this.mExecutorService = executor;
        this.mDelivery = new DownloadStatusDeliveryImpl(new Handler(Looper.getMainLooper()));
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:15,代碼來源:DownloadManager.java

示例15: createNewThreadPoolService

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
protected ThreadPoolExecutor createNewThreadPoolService(Configuration conf) {
  int nThreads = conf.getInt(
      YarnConfiguration.RM_DELEGATION_TOKEN_RENEWER_THREAD_COUNT,
      YarnConfiguration.DEFAULT_RM_DELEGATION_TOKEN_RENEWER_THREAD_COUNT);

  ThreadFactory tf = new ThreadFactoryBuilder()
      .setNameFormat("DelegationTokenRenewer #%d")
      .build();
  ThreadPoolExecutor pool =
      new ThreadPoolExecutor(nThreads, nThreads, 3L,
          TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
  pool.setThreadFactory(tf);
  pool.allowCoreThreadTimeOut(true);
  return pool;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:16,代碼來源:DelegationTokenRenewer.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.allowCoreThreadTimeOut方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。