本文整理了Java中java.util.concurrent.ThreadPoolExecutor.getThreadFactory()
方法的一些代码示例,展示了ThreadPoolExecutor.getThreadFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPoolExecutor.getThreadFactory()
方法的具体详情如下:
包路径:java.util.concurrent.ThreadPoolExecutor
类名称:ThreadPoolExecutor
方法名:getThreadFactory
[英]Returns the thread factory used to create new threads.
[中]返回用于创建新线程的线程工厂。
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public String getThreadFactoryClass() {
if (!(exec instanceof ThreadPoolExecutor))
return "";
ThreadFactory factory = ((ThreadPoolExecutor)exec).getThreadFactory();
return factory == null ? "" : factory.getClass().getName();
}
代码示例来源:origin: apache/geode
private void launchAdditionalThread(Runnable r, ThreadPoolExecutor executor) {
Thread th = executor.getThreadFactory().newThread(r);
th.start();
}
};
代码示例来源:origin: google/guava
@GwtIncompatible // TODO
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
executor.setThreadFactory(
new ThreadFactoryBuilder()
.setDaemon(true)
.setThreadFactory(executor.getThreadFactory())
.build());
}
代码示例来源:origin: robovm/robovm
/**
* Creates with given first task and thread from ThreadFactory.
* @param firstTask the first task (null if none)
*/
Worker(Runnable firstTask) {
setState(-1); // inhibit interrupts until runWorker
this.firstTask = firstTask;
this.thread = getThreadFactory().newThread(this);
}
代码示例来源:origin: google/j2objc
@GwtIncompatible // TODO
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
executor.setThreadFactory(
new ThreadFactoryBuilder()
.setDaemon(true)
.setThreadFactory(executor.getThreadFactory())
.build());
}
代码示例来源:origin: google/guava
public void testGetExitingExecutorService_executorDelegatesToOriginal() {
TestApplication application = new TestApplication();
ThreadPoolExecutor executor = mock(ThreadPoolExecutor.class);
ThreadFactory threadFactory = mock(ThreadFactory.class);
when(executor.getThreadFactory()).thenReturn(threadFactory);
application.getExitingExecutorService(executor).execute(EMPTY_RUNNABLE);
verify(executor).execute(EMPTY_RUNNABLE);
}
代码示例来源:origin: wildfly/wildfly
@GwtIncompatible // TODO
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
executor.setThreadFactory(
new ThreadFactoryBuilder()
.setDaemon(true)
.setThreadFactory(executor.getThreadFactory())
.build());
}
代码示例来源:origin: google/guava
public void testGetExitingExecutorService_shutdownHookRegistered() throws InterruptedException {
TestApplication application = new TestApplication();
ThreadPoolExecutor executor = mock(ThreadPoolExecutor.class);
ThreadFactory threadFactory = mock(ThreadFactory.class);
when(executor.getThreadFactory()).thenReturn(threadFactory);
ExecutorService unused = application.getExitingExecutorService(executor);
application.shutdown();
verify(executor).shutdown();
}
代码示例来源:origin: google/guava
public void testGetExitingExecutorService_executorSetToUseDaemonThreads() {
TestApplication application = new TestApplication();
ThreadPoolExecutor executor =
new ThreadPoolExecutor(1, 2, 3, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1));
assertNotNull(application.getExitingExecutorService(executor));
assertTrue(executor.getThreadFactory().newThread(EMPTY_RUNNABLE).isDaemon());
}
代码示例来源:origin: prestodb/presto
@GwtIncompatible // TODO
private static void useDaemonThreadFactory(ThreadPoolExecutor executor) {
executor.setThreadFactory(
new ThreadFactoryBuilder()
.setDaemon(true)
.setThreadFactory(executor.getThreadFactory())
.build());
}
代码示例来源:origin: springside/springside4
@Test
public void cachedPool() {
ThreadPoolExecutor singlePool = ThreadPoolBuilder.cachedPool().build();
assertThat(singlePool.getCorePoolSize()).isEqualTo(0);
assertThat(singlePool.getMaximumPoolSize()).isEqualTo(Integer.MAX_VALUE);
assertThat(singlePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(10);
assertThat(singlePool.getQueue()).isInstanceOf(SynchronousQueue.class);
singlePool.shutdown();
ThreadPoolExecutor sizeablePool = ThreadPoolBuilder.cachedPool().setMinSize(10).setMaxSize(100)
.setKeepAliveSecs(20).build();
assertThat(sizeablePool.getCorePoolSize()).isEqualTo(10);
assertThat(sizeablePool.getMaximumPoolSize()).isEqualTo(100);
assertThat(sizeablePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(20);
sizeablePool.shutdown();
ThreadPoolExecutor fixPoolWithNamePrefix = ThreadPoolBuilder.cachedPool().setThreadNamePrefix("cachedPool")
.build();
Thread thread = fixPoolWithNamePrefix.getThreadFactory().newThread(new Runnable() {
@Override
public void run() {
}
});
assertThat(thread.getName()).startsWith("cachedPool");
fixPoolWithNamePrefix.shutdown();
}
代码示例来源:origin: springside/springside4
@Test
public void quequablePool() {
ThreadPoolExecutor singlePool = ThreadPoolBuilder.queuableCachedPool().build();
assertThat(singlePool.getCorePoolSize()).isEqualTo(0);
assertThat(singlePool.getMaximumPoolSize()).isEqualTo(Integer.MAX_VALUE);
assertThat(singlePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(10);
assertThat(singlePool.getQueue()).isInstanceOf(ControllableQueue.class);
singlePool.shutdown();
ThreadPoolExecutor sizeablePool = ThreadPoolBuilder.queuableCachedPool().setMinSize(10).setMaxSize(100)
.setKeepAliveSecs(20).build();
assertThat(sizeablePool.getCorePoolSize()).isEqualTo(10);
assertThat(sizeablePool.getMaximumPoolSize()).isEqualTo(100);
assertThat(sizeablePool.getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(20);
sizeablePool.shutdown();
ThreadPoolExecutor fixPoolWithNamePrefix = ThreadPoolBuilder.queuableCachedPool()
.setThreadNamePrefix("queuableCachedPool").build();
Thread thread = fixPoolWithNamePrefix.getThreadFactory().newThread(new Runnable() {
@Override
public void run() {
}
});
assertThat(thread.getName()).startsWith("queuableCachedPool");
fixPoolWithNamePrefix.shutdown();
}
}
代码示例来源:origin: springside/springside4
@Test
public void scheduledPool() {
ScheduledThreadPoolExecutor singlePool = ThreadPoolBuilder.scheduledPool().build();
assertThat(singlePool.getCorePoolSize()).isEqualTo(1);
assertThat(singlePool.getMaximumPoolSize()).isEqualTo(Integer.MAX_VALUE);
singlePool.shutdown();
ScheduledThreadPoolExecutor sizeablePool = ThreadPoolBuilder.scheduledPool().setPoolSize(2).build();
assertThat(sizeablePool.getCorePoolSize()).isEqualTo(2);
assertThat(sizeablePool.getMaximumPoolSize()).isEqualTo(Integer.MAX_VALUE);
sizeablePool.shutdown();
ThreadPoolExecutor fixPoolWithNamePrefix = ThreadPoolBuilder.scheduledPool()
.setThreadNamePrefix("scheduledPool").build();
Thread thread = fixPoolWithNamePrefix.getThreadFactory().newThread(new Runnable() {
@Override
public void run() {
}
});
assertThat(thread.getName()).startsWith("scheduledPool");
fixPoolWithNamePrefix.shutdown();
}
代码示例来源:origin: springside/springside4
Thread thread = fixPoolWithlimitQueue.getThreadFactory().newThread(new Runnable() {
@Override
public void run() {
Thread thread2 = fixPoolWithNamePrefix.getThreadFactory().newThread(new Runnable() {
@Override
public void run() {
Thread thread3 = fixPoolWithNamePrefixAndDaemon.getThreadFactory().newThread(new Runnable() {
@Override
public void run() {
代码示例来源:origin: igniterealtime/Openfire
final ExecutorFilter executorFilter = new ExecutorFilter( initialSize, configuration.getMaxThreadPoolSize(), 60, TimeUnit.SECONDS );
final ThreadPoolExecutor eventExecutor = (ThreadPoolExecutor) executorFilter.getExecutor();
final ThreadFactory threadFactory = new NamedThreadFactory( name + "-thread-", eventExecutor.getThreadFactory(), true, null );
eventExecutor.setThreadFactory( threadFactory );
代码示例来源:origin: ibinti/bugvm
/**
* Creates with given first task and thread from ThreadFactory.
* @param firstTask the first task (null if none)
*/
Worker(Runnable firstTask) {
setState(-1); // inhibit interrupts until runWorker
this.firstTask = firstTask;
this.thread = getThreadFactory().newThread(this);
}
代码示例来源:origin: MobiVM/robovm
/**
* Creates with given first task and thread from ThreadFactory.
* @param firstTask the first task (null if none)
*/
Worker(Runnable firstTask) {
setState(-1); // inhibit interrupts until runWorker
this.firstTask = firstTask;
this.thread = getThreadFactory().newThread(this);
}
代码示例来源:origin: apache/cxf
@Override
protected void terminated() {
ThreadFactory f = executor.getThreadFactory();
if (f instanceof AWQThreadFactory) {
((AWQThreadFactory)f).shutdown();
}
if (watchDog != null) {
watchDog.shutdown();
}
}
};
代码示例来源:origin: org.apache.cxf/cxf-api
@Override
protected void terminated() {
ThreadFactory f = executor.getThreadFactory();
if (f instanceof AWQThreadFactory) {
((AWQThreadFactory)f).shutdown();
}
if (watchDog != null) {
watchDog.shutdown();
}
}
};
代码示例来源:origin: org.apache.cxf/cxf-core
@Override
protected void terminated() {
ThreadFactory f = executor.getThreadFactory();
if (f instanceof AWQThreadFactory) {
((AWQThreadFactory)f).shutdown();
}
if (watchDog != null) {
watchDog.shutdown();
}
}
};
内容来源于网络,如有侵权,请联系作者删除!