Search in sources :

Example 6 with PinpointThreadFactory

use of com.navercorp.pinpoint.common.util.PinpointThreadFactory in project pinpoint by naver.

the class SimpleOrderedThreadPoolTest method testExecute.

@Test
public void testExecute() throws Exception {
    SimpleOrderedThreadPool threadPool = new SimpleOrderedThreadPool(3, 100, new PinpointThreadFactory("test", true));
    int testCount = 100;
    CountDownLatch latch = new CountDownLatch(testCount);
    for (int i = 0; i < testCount; i++) {
        final int selectKey = random.nextInt();
        threadPool.execute(new TestHashSelectorRunnable(selectKey, latch));
    }
    threadPool.shutdown();
    threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(latch.getCount(), 0);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory) Test(org.junit.Test)

Example 7 with PinpointThreadFactory

use of com.navercorp.pinpoint.common.util.PinpointThreadFactory in project pinpoint by naver.

the class ZookeeperJobWorker method start.

public void start() {
    final ThreadFactory threadFactory = new PinpointThreadFactory(this.getClass().getSimpleName(), true);
    this.workerThread = threadFactory.newThread(this);
    switch(this.workerState.getCurrentState()) {
        case NEW:
            if (this.workerState.changeStateInitializing()) {
                logger.info("start() started.");
                workerState.changeStateStarted();
                this.workerThread.start();
                logger.info("start() completed.");
                break;
            }
        case INITIALIZING:
            logger.info("start() failed. cause: already initializing.");
            break;
        case STARTED:
            logger.info("start() failed. cause: already initializing.");
            break;
        case DESTROYING:
            throw new IllegalStateException("Already destroying.");
        case STOPPED:
            throw new IllegalStateException(ClassUtils.simpleClassName(this) + " start() failed. caused:Already stopped.");
        case ILLEGAL_STATE:
            throw new IllegalStateException(ClassUtils.simpleClassName(this) + " start() failed. caused:Invalid State.");
    }
}
Also used : PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory)

Example 8 with PinpointThreadFactory

use of com.navercorp.pinpoint.common.util.PinpointThreadFactory in project pinpoint by naver.

the class PinpointStarter method registerShutdownHook.

private void registerShutdownHook(final Agent pinpointAgent) {
    final Runnable stop = new Runnable() {

        @Override
        public void run() {
            pinpointAgent.stop();
        }
    };
    PinpointThreadFactory pinpointThreadFactory = new PinpointThreadFactory("Pinpoint-shutdown-hook");
    Thread thread = pinpointThreadFactory.newThread(stop);
    Runtime.getRuntime().addShutdownHook(thread);
}
Also used : PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory)

Example 9 with PinpointThreadFactory

use of com.navercorp.pinpoint.common.util.PinpointThreadFactory in project pinpoint by naver.

the class HbaseTemplate2 method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    Configuration configuration = getConfiguration();
    Assert.notNull(configuration, "configuration is required");
    Assert.notNull(getTableFactory(), "tableFactory is required");
    PinpointThreadFactory parallelScannerThreadFactory = new PinpointThreadFactory("Pinpoint-parallel-scanner");
    if (this.maxThreadsPerParallelScan <= 1) {
        this.enableParallelScan = false;
        this.executor = Executors.newSingleThreadExecutor(parallelScannerThreadFactory);
    } else {
        this.executor = ExecutorFactory.newFixedThreadPool(this.maxThreads, 1024, parallelScannerThreadFactory);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory)

Example 10 with PinpointThreadFactory

use of com.navercorp.pinpoint.common.util.PinpointThreadFactory in project pinpoint by naver.

the class PinpointThreadFactoryTest method testCreateThreadFactory.

@Test
public void testCreateThreadFactory() throws Exception {
    final AtomicInteger counter = new AtomicInteger(0);
    PinpointThreadFactory pinpoint = new PinpointThreadFactory("pinpoint");
    Thread thread = pinpoint.newThread(new Runnable() {

        @Override
        public void run() {
            counter.getAndIncrement();
        }
    });
    thread.start();
    thread.join();
    Assert.assertEquals(counter.get(), 1);
    String threadName = thread.getName();
    logger.debug(threadName);
    Assert.assertTrue(threadName.startsWith("pinpoint("));
    Assert.assertTrue(threadName.endsWith(")"));
    Thread thread2 = pinpoint.newThread(new Runnable() {

        @Override
        public void run() {
        }
    });
    logger.debug(thread2.getName());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PinpointThreadFactory(com.navercorp.pinpoint.common.util.PinpointThreadFactory) Test(org.junit.Test)

Aggregations

PinpointThreadFactory (com.navercorp.pinpoint.common.util.PinpointThreadFactory)13 ThreadFactory (java.util.concurrent.ThreadFactory)4 DatagramPacketFactory (com.navercorp.pinpoint.collector.util.DatagramPacketFactory)2 ExecutorService (java.util.concurrent.ExecutorService)2 NioWorkerPool (org.jboss.netty.channel.socket.nio.NioWorkerPool)2 Test (org.junit.Test)2 MonitoredExecutorService (com.navercorp.pinpoint.collector.monitor.MonitoredExecutorService)1 SimpleOrderedThreadPool (com.navercorp.pinpoint.web.util.SimpleOrderedThreadPool)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Configuration (org.apache.hadoop.conf.Configuration)1 TException (org.apache.thrift.TException)1 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)1 NioClientBossPool (org.jboss.netty.channel.socket.nio.NioClientBossPool)1 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)1 NioServerBossPool (org.jboss.netty.channel.socket.nio.NioServerBossPool)1 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)1