Example usage for java.lang Thread getName

List of usage examples for java.lang Thread getName

Introduction

In this page you can find the example usage for java.lang Thread getName.

Prototype

public final String getName() 

Source Link

Document

Returns this thread's name.

Usage

From source file:com.baidu.fsg.uid.utils.NamingThreadFactory.java

@Override
public Thread newThread(Runnable r) {
    Thread thread = new Thread(r);
    thread.setDaemon(this.daemon);

    // If there is no specified name for thread, it will auto detect using the invoker classname instead.
    // Notice that auto detect may cause some performance overhead
    String prefix = this.name;
    if (StringUtils.isBlank(prefix)) {
        prefix = getInvoker(2);//  ww  w  .j a v  a2  s .  c o m
    }
    thread.setName(prefix + "-" + getSequence(prefix));

    // no specified uncaughtExceptionHandler, just do logging.
    if (this.uncaughtExceptionHandler != null) {
        thread.setUncaughtExceptionHandler(this.uncaughtExceptionHandler);
    } else {
        thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
            public void uncaughtException(Thread t, Throwable e) {
                LOGGER.error("unhandled exception in thread: " + t.getId() + ":" + t.getName(), e);
            }
        });
    }

    return thread;
}

From source file:org.trafodion.rest.ResourceChecker.java

public void logInfo(Phase phase, String tagLine) {
    long threadCount = rc.getThreadsCount(phase);
    LOG.info(tagLine + ": " + threadCount + " threads"
            + (initialThreadsCount > 0 ? " (was " + initialThreadsCount + "), " : ", ")
            + rc.getOpenFileDescriptorCount() + " file descriptors"
            + (initialFileHandlesCount > 0 ? " (was " + initialFileHandlesCount + "). " : " ")
            + (initialThreadsCount > 0 && threadCount > initialThreadsCount ? " -thread leak?- " : "")
            + (initialFileHandlesCount > 0 && rc.getOpenFileDescriptorCount() > initialFileHandlesCount
                    ? " -file handle leak?- "
                    : ""));
    if (phase == Phase.END) {
        Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
        if (stackTraces.size() > initialThreadNames.size()) {
            for (Thread t : stackTraces.keySet()) {
                if (!initialThreadNames.contains(t.getName())) {
                    LOG.info(tagLine + ": potentially hanging thread - " + t.getName());
                    StackTraceElement[] stackElements = stackTraces.get(t);
                    for (StackTraceElement ele : stackElements) {
                        LOG.info("\t" + ele);
                    }/*from  www.j  a  v a 2 s.  c  o m*/
                }
            }
        }
    }
}

From source file:com.sixt.service.framework.kafka.messaging.KafkaIntegrationTest.java

private void brutallyKillConsumer(String victimName) {
    int nbThreads = Thread.activeCount();
    Thread[] threads = new Thread[nbThreads];
    Thread.enumerate(threads);//from  ww w.  j a  v  a 2s. c o m

    for (Thread t : threads) {
        if (t.getName().equals(victimName)) {
            logger.error("BOOM: Killing consumer thread {}", victimName);
            t.stop(); // used by intention despite deprecation
        }
    }
}

From source file:com.alibaba.wasp.master.GeneralBulkAssigner.java

@Override
protected UncaughtExceptionHandler getUncaughtExceptionHandler() {
    return new UncaughtExceptionHandler() {
        @Override/*from   w w  w  .  j  a va2  s.c o m*/
        public void uncaughtException(Thread t, Throwable e) {
            LOG.warn("Assigning entityGroups in " + t.getName(), e);
        }
    };
}

From source file:au.edu.uq.cmm.paul.Paul.java

private void setupDefaultUncaughtExceptionHandler() {
    if (Thread.getDefaultUncaughtExceptionHandler() == null) {
        LOG.info("Setting the uncaught exception handler");
    } else {/*from  ww  w  .  j  ava  2  s  . c om*/
        LOG.info("Changing the uncaught exception handler");
    }
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            LOG.error("Thread " + t.getName() + " died with an uncaught exception", e);
        }
    });
}

From source file:org.apache.hadoop.hbase.master.GeneralBulkAssigner.java

@Override
protected UncaughtExceptionHandler getUncaughtExceptionHandler() {
    return new UncaughtExceptionHandler() {
        @Override/*from ww  w .ja va  2 s  . c o m*/
        public void uncaughtException(Thread t, Throwable e) {
            LOG.warn("Assigning regions in " + t.getName(), e);
        }
    };
}

From source file:io.wcm.caravan.io.http.impl.CaravanHttpClientThreadingTest.java

@Test
public void test_responseEmissionOnHystrixThread() throws InterruptedException {

    CaravanHttpRequest request = new CaravanHttpRequestBuilder(SERVICE_NAME).append(HTTP_200_URI).build();

    // we don't call #observeOn here, so the response should be emitted with the hystrix threadpool
    // that we have specified in the CaravanHttpServiceConfig
    Observable<CaravanHttpResponse> rxResponse = underTest.execute(request);

    Thread emissionThread = subscribeWaitAndGetEmissionThread(rxResponse);

    // check that the response was emitted on a hystrix- thread
    assertTrue(emissionThread.getName().startsWith("hystrix-" + HYSTRIX_THREADPOOL_NAME));
}

From source file:org.apache.hadoop.corona.Scheduler.java

/**
 * Start the scheduling as well as the reloadable configuration manager.
 *///from  w  ww . ja v a2  s.  c o m
public void start() {
    for (Thread schedulerForType : schedulersForTypes.values()) {
        LOG.info("Starting " + schedulerForType.getName());
        schedulerForType.start();
    }
    configManager.start();
}

From source file:com.googlecode.arit.threads.ThreadScanner.java

public void clean(ClassLoader classLoader) {
    for (Thread thread : ThreadUtils.getAllThreads()) {
        if (thread.getContextClassLoader() == classLoader) {
            thread.setContextClassLoader(String.class.getClassLoader());
            LOG.info("Unset context class loader for thread " + thread.getName());
        }//from   ww w. j  a va2 s.c  o m
    }
}

From source file:io.wcm.caravan.io.http.impl.CaravanHttpClientThreadingTest.java

@Test
public void test_responseEmissionOnComputationThread() throws InterruptedException {

    CaravanHttpRequest request = new CaravanHttpRequestBuilder(SERVICE_NAME).append(HTTP_200_URI).build();

    // we want the HTTP request to be executed using the hystrix threadpool, but the response
    // should be emitted on the computations thread
    Observable<CaravanHttpResponse> rxResponse = underTest.execute(request).observeOn(Schedulers.computation());

    Thread emissionThread = subscribeWaitAndGetEmissionThread(rxResponse);

    // check that the response was emitted on a rx computation thread
    assertTrue(emissionThread.getName().toLowerCase().contains("computation"));
}