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


Java ThreadPoolExecutor.setThreadFactory方法代码示例

本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.setThreadFactory方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadPoolExecutor.setThreadFactory方法的具体用法?Java ThreadPoolExecutor.setThreadFactory怎么用?Java ThreadPoolExecutor.setThreadFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.setThreadFactory方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serviceInit

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@Override
protected void serviceInit(Configuration conf) throws Exception {
  int threadCount = conf.getInt(
      YarnConfiguration.RM_AMLAUNCHER_THREAD_COUNT,
      YarnConfiguration.DEFAULT_RM_AMLAUNCHER_THREAD_COUNT);
  ThreadFactory tf = new ThreadFactoryBuilder()
      .setNameFormat("ApplicationMasterLauncher #%d")
      .build();
  launcherPool = new ThreadPoolExecutor(threadCount, threadCount, 1,
      TimeUnit.HOURS, new LinkedBlockingQueue<Runnable>());
  launcherPool.setThreadFactory(tf);

  Configuration newConf = new YarnConfiguration(conf);
  newConf.setInt(CommonConfigurationKeysPublic.
          IPC_CLIENT_CONNECT_MAX_RETRIES_ON_SOCKET_TIMEOUTS_KEY,
      conf.getInt(YarnConfiguration.RM_NODEMANAGER_CONNECT_RETIRES,
          YarnConfiguration.DEFAULT_RM_NODEMANAGER_CONNECT_RETIRES));
  setConfig(newConf);
  super.serviceInit(newConf);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:ApplicationMasterLauncher.java

示例2: ReadaheadPool

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
private ReadaheadPool() {
  pool = new ThreadPoolExecutor(POOL_SIZE, MAX_POOL_SIZE, 3L, TimeUnit.SECONDS,
      new ArrayBlockingQueue<Runnable>(CAPACITY));
  pool.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
  pool.setThreadFactory(new ThreadFactoryBuilder()
    .setDaemon(true)
    .setNameFormat("Readahead Thread #%d")
    .build());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:10,代码来源:ReadaheadPool.java

示例3: useDaemonThreadFactory

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
@GwtIncompatible // TODO
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
  executor.setThreadFactory(
      new ThreadFactoryBuilder()
          .setDaemon(true)
          .setThreadFactory(executor.getThreadFactory())
          .build());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:MoreExecutors.java

示例4: 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

示例5: testSetThreadFactory

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setThreadFactory sets the thread factory returned by getThreadFactory
 */
public void testSetThreadFactory() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(1, 2,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        ThreadFactory threadFactory = new SimpleThreadFactory();
        p.setThreadFactory(threadFactory);
        assertSame(threadFactory, p.getThreadFactory());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ThreadPoolExecutorTest.java

示例6: testSetThreadFactoryNull

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setThreadFactory(null) throws NPE
 */
public void testSetThreadFactoryNull() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(1, 2,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        try {
            p.setThreadFactory(null);
            shouldThrow();
        } catch (NullPointerException success) {}
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ThreadPoolExecutorTest.java

示例7: testSetThreadFactory

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setThreadFactory sets the thread factory returned by getThreadFactory
 */
public void testSetThreadFactory() {
    final ThreadPoolExecutor p =
        new CustomTPE(1, 2,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        ThreadFactory threadFactory = new SimpleThreadFactory();
        p.setThreadFactory(threadFactory);
        assertSame(threadFactory, p.getThreadFactory());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ThreadPoolExecutorSubclassTest.java

示例8: testSetThreadFactoryNull

import java.util.concurrent.ThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * setThreadFactory(null) throws NPE
 */
public void testSetThreadFactoryNull() {
    final ThreadPoolExecutor p =
        new CustomTPE(1, 2,
                      LONG_DELAY_MS, MILLISECONDS,
                      new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        try {
            p.setThreadFactory(null);
            shouldThrow();
        } catch (NullPointerException success) {}
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ThreadPoolExecutorSubclassTest.java


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