Search in sources :

Example 86 with ThreadFactory

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);
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) NokogiriBlockingQueueInputStream(nokogiri.internals.NokogiriBlockingQueueInputStream)

Example 87 with ThreadFactory

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);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Before(org.junit.Before)

Example 88 with ThreadFactory

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);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) FastForward(eu.toolchain.ffwd.FastForward) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder)

Example 89 with ThreadFactory

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;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder)

Example 90 with ThreadFactory

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();
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler) Test(org.junit.Test)

Aggregations

ThreadFactory (java.util.concurrent.ThreadFactory)250 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)47 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)46 ExecutorService (java.util.concurrent.ExecutorService)45 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)35 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)21 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)19 Test (org.junit.Test)17 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)16 Future (java.util.concurrent.Future)15 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)13 ArrayList (java.util.ArrayList)13 LoggingThreadGroup (org.apache.geode.internal.logging.LoggingThreadGroup)12 IOException (java.io.IOException)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 ExecutionException (java.util.concurrent.ExecutionException)9 Executor (java.util.concurrent.Executor)9 ChannelFuture (io.netty.channel.ChannelFuture)8 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)8 SynchronousQueue (java.util.concurrent.SynchronousQueue)7