use of java.util.concurrent.ThreadFactory in project nokogiri by sparklemotion.
the class HtmlSaxPushParser method initialize_task.
private void initialize_task(ThreadContext context) throws IOException {
if (futureTask == null || stream == null) {
stream = new NokogiriBlockingQueueInputStream();
parserTask = new ParserTask(context, saxParser);
futureTask = new FutureTask<HtmlSaxParserContext>(parserTask);
executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("HtmlSaxPushParser");
t.setDaemon(true);
return t;
}
});
executor.submit(futureTask);
}
}
use of java.util.concurrent.ThreadFactory in project helios by spotify.
the class FastForwardReporterTest method setUp.
@Before
public void setUp() throws Exception {
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).build();
this.executor = Executors.newSingleThreadScheduledExecutor(threadFactory);
this.reporter = new FastForwardReporter(ffwd, metricRegistry, executor, "helios.test", // these interval values do not matter for this test:
30, TimeUnit.SECONDS, Collections::emptyMap);
}
use of java.util.concurrent.ThreadFactory in project helios by spotify.
the class FastForwardReporter method create.
/**
* Overload of {@link #create(MetricRegistry, Optional, String, int)} which allows for setting
* additional attributes in each reported metric.
*
* <p>The additional attributes are modeled as a Supplier to allow for attributes that might
* change values at runtime.
*/
public static FastForwardReporter create(MetricRegistry registry, Optional<HostAndPort> address, String metricKey, int intervalSeconds, Supplier<Map<String, String>> additionalAttributes) throws SocketException, UnknownHostException {
final FastForward ff;
if (address.isPresent()) {
ff = FastForward.setup(address.get().getHostText(), address.get().getPort());
} else {
ff = FastForward.setup();
}
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("fast-forward-reporter-%d").build();
final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
return new FastForwardReporter(ff, registry, executorService, metricKey, intervalSeconds, TimeUnit.SECONDS, additionalAttributes);
}
use of java.util.concurrent.ThreadFactory in project reflections by ronmamo.
the class ConfigurationBuilder method useParallelExecutor.
/** sets the executor service used for scanning to ThreadPoolExecutor with core size as the given availableProcessors parameter.
* the executor service spawns daemon threads by default.
* <p>default is ThreadPoolExecutor with a single core */
public ConfigurationBuilder useParallelExecutor(final int availableProcessors) {
ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("org.reflections-scanner-%d").build();
setExecutorService(Executors.newFixedThreadPool(availableProcessors, factory));
return this;
}
use of java.util.concurrent.ThreadFactory in project spring-framework by spring-projects.
the class ScheduledExecutorFactoryBeanTests method testShutdownIsPropagatedToTheExecutorOnDestroy.
@Test
@SuppressWarnings("serial")
public void testShutdownIsPropagatedToTheExecutorOnDestroy() throws Exception {
final ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@Override
protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
return executor;
}
};
factory.setScheduledExecutorTasks(new ScheduledExecutorTask[] { new NoOpScheduledExecutorTask() });
factory.setWaitForTasksToCompleteOnShutdown(true);
factory.afterPropertiesSet();
factory.destroy();
verify(executor).shutdown();
}
Aggregations