Search in sources :

Example 51 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project neo4j by neo4j.

the class DaemonThreadFactory method newThread.

@Override
public Thread newThread(Runnable r) {
    ThreadFactory def = Executors.defaultThreadFactory();
    Thread thread = def.newThread(r);
    thread.setDaemon(true);
    return thread;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory)

Example 52 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project pinpoint by naver.

the class StandbySpanStreamDataSendWorker method start.

public void start() {
    final ThreadFactory threadFactory = new PinpointThreadFactory(this.getClass().getSimpleName(), true);
    this.workerThread = threadFactory.newThread(this);
    logger.info("start() started.");
    if (!workerThread.isAlive()) {
        this.isStarted = true;
        this.workerThread.start();
        logger.info("start() completed.");
    } else {
        logger.info("start() failed. caused:already started.", this.getClass().getSimpleName());
    }
}
Also used : PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory)

Example 53 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project pinpoint by naver.

the class BufferedUdpDataSender method startScheduledFlush.

private Thread startScheduledFlush() {
    final ThreadFactory threadFactory = new PinpointThreadFactory(SCHEDULED_FLUSH, true);
    final Thread thread = threadFactory.newThread(new Runnable() {

        @Override
        public void run() {
            final Thread currentThread = Thread.currentThread();
            while (!currentThread.isInterrupted()) {
                try {
                    chunkHeaderBufferedSerializer.flush();
                } catch (TException e) {
                    logger.warn("Failed to flush. caused={}", e.getMessage(), e);
                }
                try {
                    TimeUnit.MILLISECONDS.sleep(1000);
                } catch (InterruptedException ignored) {
                    currentThread.interrupt();
                }
            }
            logger.info("stop ScheduledFlush {} - {}", currentThread.getName(), currentThread.getId());
        }
    });
    logger.info("stop ScheduledFlush {} - {}", thread.getName(), thread.getId());
    thread.start();
    return thread;
}
Also used : TException(org.apache.thrift.TException) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory)

Example 54 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project jersey by jersey.

the class AbstractThreadPoolProvider method createThreadFactory.

private ThreadFactory createThreadFactory() {
    final ThreadFactoryBuilder factoryBuilder = new ThreadFactoryBuilder().setNameFormat(name + "-%d").setUncaughtExceptionHandler(new JerseyProcessingUncaughtExceptionHandler());
    final ThreadFactory backingThreadFactory = getBackingThreadFactory();
    if (backingThreadFactory != null) {
        factoryBuilder.setThreadFactory(backingThreadFactory);
    }
    return factoryBuilder.build();
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) JerseyProcessingUncaughtExceptionHandler(org.glassfish.jersey.process.JerseyProcessingUncaughtExceptionHandler) ThreadFactoryBuilder(org.glassfish.jersey.internal.guava.ThreadFactoryBuilder)

Example 55 with ThreadFactory

use of java.util.concurrent.ThreadFactory in project dropwizard by dropwizard.

the class LifecycleEnvironmentTest method executorServiceThreadFactory.

@Test
public void executorServiceThreadFactory() throws ExecutionException, InterruptedException {
    final String expectedName = "DropWizard ThreadFactory Test";
    final String expectedNamePattern = expectedName + "-%d";
    final ThreadFactory tfactory = (new ThreadFactoryBuilder()).setDaemon(false).setNameFormat(expectedNamePattern).build();
    final ExecutorService executorService = environment.executorService("Dropwizard Service", tfactory).build();
    final Future<Boolean> isFactoryInUse = executorService.submit(() -> Thread.currentThread().getName().startsWith(expectedName));
    assertThat(isFactoryInUse.get()).isTrue();
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) 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