本文整理汇总了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);
}
示例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());
}
示例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());
}
示例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;
}
示例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());
}
}
示例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) {}
}
}
示例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());
}
}
示例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) {}
}
}