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:controller.servlet.ImportAmenities.java

/**
 * Notificacin de fin del hilo lanzado.//w w w.j av a 2  s  . c  o m
 * @param thread el hilo que termina.
 */
@Override
public void notifyOfThreadComplete(Thread thread) {
    Logger.getLogger(ImportAmenities.class.getName()).log(Level.INFO, "{0} ended successfully",
            thread.getName());

}

From source file:org.bonitasoft.engine.LocalServerTestsInitializer.java

private boolean isExpectedThread(final Thread thread) {
    final String name = thread.getName();
    final ThreadGroup threadGroup = thread.getThreadGroup();
    if (threadGroup != null && threadGroup.getName().equals("system")) {
        return true;
    }/*from ww  w.  j  a  va  2 s.  c o  m*/
    final List<String> startWithFilter = Arrays.asList("H2 ", "Timer-0" /* postgres driver related */, "BoneCP",
            "bitronix", "main", "Reference Handler", "Signal Dispatcher", "Finalizer",
            "com.google.common.base.internal.Finalizer"/* guava, used by bonecp */, "process reaper",
            "ReaderThread", "Abandoned connection cleanup thread", "AWT-AppKit"/* bonecp related */,
            "Monitor Ctrl-Break"/* Intellij */);
    for (final String prefix : startWithFilter) {
        if (name.startsWith(prefix)) {
            return true;
        }
    }
    return false;
}

From source file:net.bluehornreader.service.Service.java

public void waitForThreadsToFinish() {
    long start = System.currentTimeMillis();
    for (;;) {/*www . j  ava  2  s. c  om*/
        boolean foundAlive = false;
        if (isAlive()) {
            foundAlive = true;
            LOG.info(String.format("Thread %s is still alive", getName()));
            synchronized (this) {
                notify();
            }
        }
        for (Thread thread : getChildThreads()) {
            if (thread.isAlive()) {
                foundAlive = true;
                LOG.info(String.format("Thread %s is still alive", thread.getName()));
                synchronized (thread) { //ttt2 make sure this works, as Idea complains: create a separate test case; (the thing is that the object is not
                    // local, but taken from a global collection)
                    thread.notify();
                }
            }
        }
        if (foundAlive) {
            try {
                if (System.currentTimeMillis() - start > 10000) { // ttt2 maybe make configurable
                    LOG.warn("Some threads are still running. Giving up on shutting them down.");
                    return;
                }

                Thread.sleep(1000);
            } catch (InterruptedException e) {
                LOG.error("Exception sleeping while trying to shut down child threads", e);
            }
        } else {
            return;
        }
    }
}

From source file:com.bah.lucene.BlockCacheDirectoryFactoryV2.java

public BlockCacheDirectoryFactoryV2(Configuration configuration, long totalNumberOfBytes) {

    final int fileBufferSizeInt = configuration.getInt(BLUR_SHARD_BLOCK_CACHE_V2_FILE_BUFFER_SIZE, 8192);
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_FILE_BUFFER_SIZE, fileBufferSizeInt));
    final int cacheBlockSizeInt = configuration.getInt(BLUR_SHARD_BLOCK_CACHE_V2_CACHE_BLOCK_SIZE, 8192);
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_CACHE_BLOCK_SIZE, cacheBlockSizeInt));

    final Map<String, Integer> cacheBlockSizeMap = new HashMap<String, Integer>();
    for (Entry<String, String> prop : configuration) {
        String key = prop.getKey();
        if (key.startsWith(BLUR_SHARD_BLOCK_CACHE_V2_CACHE_BLOCK_SIZE_PREFIX)) {
            String value = prop.getValue();
            int cacheBlockSizeForFile = Integer.parseInt(value);
            String fieldType = key.substring(BLUR_SHARD_BLOCK_CACHE_V2_CACHE_BLOCK_SIZE_PREFIX.length());

            cacheBlockSizeMap.put(fieldType, cacheBlockSizeForFile);
            LOG.info(//from ww w  .  j ava2 s . c  o m
                    MessageFormat.format("{0}={1} for file type [{2}]", key, cacheBlockSizeForFile, fieldType));
        }
    }

    final STORE store = STORE.valueOf(configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_STORE, OFF_HEAP));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_STORE, store));

    final Set<String> cachingFileExtensionsForRead = getSet(
            configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_READ_CACHE_EXT, DEFAULT_VALUE));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_READ_CACHE_EXT,
            cachingFileExtensionsForRead));

    final Set<String> nonCachingFileExtensionsForRead = getSet(
            configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_READ_NOCACHE_EXT, DEFAULT_VALUE));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_READ_NOCACHE_EXT,
            nonCachingFileExtensionsForRead));

    final boolean defaultReadCaching = configuration.getBoolean(BLUR_SHARD_BLOCK_CACHE_V2_READ_DEFAULT, true);
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_READ_DEFAULT, defaultReadCaching));

    final Set<String> cachingFileExtensionsForWrite = getSet(
            configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_WRITE_CACHE_EXT, DEFAULT_VALUE));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_WRITE_CACHE_EXT,
            cachingFileExtensionsForWrite));

    final Set<String> nonCachingFileExtensionsForWrite = getSet(
            configuration.get(BLUR_SHARD_BLOCK_CACHE_V2_WRITE_NOCACHE_EXT, DEFAULT_VALUE));
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_WRITE_NOCACHE_EXT,
            nonCachingFileExtensionsForWrite));

    final boolean defaultWriteCaching = configuration.getBoolean(BLUR_SHARD_BLOCK_CACHE_V2_WRITE_DEFAULT, true);
    LOG.info(MessageFormat.format("{0}={1}", BLUR_SHARD_BLOCK_CACHE_V2_WRITE_DEFAULT, defaultWriteCaching));

    Size fileBufferSize = new Size() {
        @Override
        public int getSize(CacheDirectory directory, String fileName) {
            return fileBufferSizeInt;
        }
    };

    Size cacheBlockSize = new Size() {
        @Override
        public int getSize(CacheDirectory directory, String fileName) {
            String ext = getExt(fileName);
            Integer size = cacheBlockSizeMap.get(ext);
            if (size != null) {
                return size;
            }
            return cacheBlockSizeInt;
        }
    };

    FileNameFilter readFilter = new FileNameFilter() {
        @Override
        public boolean accept(CacheDirectory directory, String fileName) {
            String ext = getExt(fileName);
            if (cachingFileExtensionsForRead.contains(ext)) {
                return true;
            } else if (nonCachingFileExtensionsForRead.contains(ext)) {
                return false;
            }
            return defaultReadCaching;
        }
    };

    FileNameFilter writeFilter = new FileNameFilter() {
        @Override
        public boolean accept(CacheDirectory directory, String fileName) {
            String ext = getExt(fileName);
            if (cachingFileExtensionsForWrite.contains(ext)) {
                return true;
            } else if (nonCachingFileExtensionsForWrite.contains(ext)) {
                return false;
            }
            return defaultWriteCaching;
        }
    };

    Quiet quiet = new Quiet() {
        @Override
        public boolean shouldBeQuiet(CacheDirectory directory, String fileName) {
            Thread thread = Thread.currentThread();
            String name = thread.getName();
            if (name.startsWith(SHARED_MERGE_SCHEDULER)) {
                return true;
            }
            return false;
        }
    };

    _cache = new BaseCache(totalNumberOfBytes, fileBufferSize, cacheBlockSize, readFilter, writeFilter, quiet,
            store);
}

From source file:org.apache.hadoop.hbase.regionserver.transactional.TransactionalRegionServer.java

@Override
protected void init(final MapWritable c) throws IOException {
    super.init(c);
    String n = Thread.currentThread().getName();
    UncaughtExceptionHandler handler = new UncaughtExceptionHandler() {
        public void uncaughtException(final Thread t, final Throwable e) {
            abort();//from w ww  .  j av  a 2  s.c o  m
            LOG.fatal("Set stop flag in " + t.getName(), e);
        }
    };
    Threads.setDaemonThreadRunning(this.cleanOldTransactionsThread, n + ".oldTransactionCleaner", handler);
    Threads.setDaemonThreadRunning(this.transactionLeases, "Transactional leases");

}

From source file:eu.stratosphere.nephele.profiling.impl.TaskManagerProfilerImpl.java

public void unregisterMainThreadFromCPUProfiling(Environment environment, Thread thread) {

    synchronized (this.monitoredThreads) {
        LOG.debug("Unregistering thread " + thread.getName() + " from CPU monitoring");
        final EnvironmentThreadSet environmentThreadSet = this.monitoredThreads.remove(environment);
        if (environmentThreadSet != null) {

            if (environmentThreadSet.getMainThread() != thread) {
                LOG.error("The thread " + thread.getName() + " is not the main thread of this environment");
            }/*from   www.ja v a 2 s.  c  o  m*/

            if (environmentThreadSet.getNumberOfUserThreads() > 0) {
                LOG.error("Thread " + environmentThreadSet.getMainThread().getName()
                        + " has still unfinished user threads!");
            }
        }
    }
}

From source file:org.berlin.crawl.bom.BotTrueCrawler.java

public void launch() {
    // Each bot crawler will launch in a separate thread //
    // Each true crawler will have a blocking queue for added 
    // bot links to process 
    loadIgnores();/*  w  w  w .  j av a2s . com*/
    final BotTrueCrawlerThread thread = new BotTrueCrawlerThread();
    final Thread t = new Thread(thread);
    final String mngl = (this.firstLink.getHost().length() >= 12) ? this.firstLink.getHost().substring(0, 10)
            : this.firstLink.getHost();
    t.setName(t.getName() + "-TrueCrawl-" + mngl);
    t.start();
    queue.launchReportSystem();
}

From source file:com.runwaysdk.dataaccess.database.general.ProcessReader.java

/**
 * Handles errors from the underlying threads
 * //from w  ww  . j  a  v a2 s .  c  om
 * @param thread
 * @param t
 */
@Override
public void uncaughtException(Thread thread, Throwable t) {
    log.error(thread, t);

    this.threadThrowables.put(thread.getName(), t);
}

From source file:at.sti2.sparkwave.SparkwaveKernel.java

/**
 * Starts all relevant threads for a pattern and keeps track of them
 * @param pattern//w ww. j  a  va2s. c o m
 */
public void addProcessorThread(Pattern pattern) {

    //Create SparkwaveNetwork
    SparkwaveNetwork sparkwaveNetwork = new SparkwaveNetwork(pattern);
    sparkwaveNetwork.init();

    //Every pattern gets its own queue
    BlockingQueue<Triple> queue = new ArrayBlockingQueue<Triple>(10);
    queues.add(queue);

    //Create SparkwaveProcessorThread
    ProcessorThread sparkwaveProcessor = new ProcessorThread(sparkwaveNetwork, queue);
    Thread thread = new Thread(sparkwaveProcessor);
    thread.setName("Processor-" + thread.getName());
    thread.start();

    patternThreadMap.put(pattern, thread);
    patternQueueMap.put(pattern, queue);
    idPatternMap.put(pattern.getId(), pattern);

}

From source file:org.bonitasoft.engine.LocalServerTestsInitializer.java

private void printThread(final Thread thread) {
    System.out.println("\n");
    System.out.println("Thread is still alive:" + thread.getName());
    for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
        System.out.println("        at " + stackTraceElement.toString());
    }/*  ww  w  .  j a v  a  2s.  c  o  m*/
}