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:org.apache.hadoop.hbase.procedure2.RemoteProcedureDispatcher.java

protected UncaughtExceptionHandler getUncaughtExceptionHandler() {
    return new UncaughtExceptionHandler() {
        @Override// w w w . j a  va 2s  .c  o  m
        public void uncaughtException(Thread t, Throwable e) {
            LOG.warn("Failed to execute remote procedures " + t.getName(), e);
        }
    };
}

From source file:org.apache.stratos.common.concurrent.locks.ReadWriteLock.java

/**
 * releases read lock//  w w w  .  j  a  v a2  s  .com
 */
public void releaseReadLock() {
    Thread currentThread = Thread.currentThread();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Releasing read lock: [lock-name] %s [thread-id] %d [thread-name] %s",
                getName(), currentThread.getId(), currentThread.getName()));
    }

    lock.readLock().unlock();

    if (readWriteLockMonitorEnabled) {
        Map<LockType, LockMetadata> lockTypeLongMap = getLockTypeLongMap(currentThread.getId());
        lockTypeLongMap.remove(LockType.Read);
    }

    if (log.isDebugEnabled()) {
        log.debug(String.format("Read lock released: [lock-name] %s [thread-id] %d [thread-name] %s", getName(),
                currentThread.getId(), currentThread.getName()));
    }
}

From source file:org.apache.stratos.common.concurrent.locks.ReadWriteLock.java

/**
 * acquires read lock/*  w ww  .  j  av a2 s  . c o m*/
 */
public void acquireReadLock() {
    Thread currentThread = Thread.currentThread();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Acquiring read lock: [lock-name] %s [thread-id] %d [thread-name] %s",
                getName(), currentThread.getId(), currentThread.getName()));
    }

    lock.readLock().lock();

    if (readWriteLockMonitorEnabled) {
        Map<LockType, LockMetadata> lockTypeLongMap = getLockTypeLongMap(currentThread.getId());
        LockMetadata lockMetadata = new LockMetadata(getName(), LockType.Read, currentThread.getId(),
                currentThread.getName(), currentThread.getStackTrace(), System.currentTimeMillis());
        lockTypeLongMap.put(lockMetadata.getLockType(), lockMetadata);
    }

    if (log.isDebugEnabled()) {
        log.debug(String.format("Read lock acquired: [lock-name] %s [thread-id] %d [thread-name] %s", getName(),
                currentThread.getId(), currentThread.getName()));
    }
}

From source file:com.urremote.classifier.common.ExceptionHandler.java

public void uncaughtException(Thread t, Throwable e) {
    String timestamp = String.valueOf(System.currentTimeMillis());
    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    printWriter.println("Exception Thrown By Thread:" + t.getId() + " '" + t.getName() + "'");
    e.printStackTrace(printWriter);/*w  w w. j  a  v a  2 s .com*/
    String stacktrace = result.toString();
    printWriter.close();
    String filename = timestamp + ".stacktrace";
    writeToFile(stacktrace, filename);

    FlurryAgent.onError(e.getMessage(), stacktrace, e.getClass().getCanonicalName());
    //sendToServer(stacktrace, filename);

    defaultUEH.uncaughtException(t, e);
}

From source file:org.nuxeo.ecm.core.management.jtajca.internal.DefaultTransactionMonitor.java

@Override
public void threadAssociated(Transaction tx) {
    long now = System.currentTimeMillis();
    Object key = tm.getTransactionKey();
    MDC.put("tx", id(key));
    Stopwatch sw = SimonManager.getStopwatch("tx");
    final Thread thread = Thread.currentThread();
    DefaultTransactionStatistics info = new DefaultTransactionStatistics(key);
    info.split = sw.start();//w w w. j  av a 2  s  . c  o m
    info.threadName = thread.getName();
    info.status = TransactionStatistics.Status.fromTx(tx);

    info.startTimestamp = now;
    info.startCapturedContext = new Throwable("** start invoke context **");
    synchronized (this) {
        activeStatistics.put(key, info);
    }
    tm.registerInterposedSynchronization(this); // register end status
    if (log.isTraceEnabled()) {
        log.trace(info.toString());
    }
}

From source file:net.sf.ehcache.constructs.web.filter.CachingFilter.java

/**
 * Check that this caching filter is not being reentered by the same recursively.
 * Recursive calls will block indefinitely because the first request has not yet
 * unblocked the cache./*w w  w . j  a  v  a  2  s . c  om*/
 * <p/>
 * This condition usually indicates an error in filter chaining or RequestDispatcher
 * dispatching.
 *
 * @param httpRequest
 * @throws FilterNonReentrantException if reentry is detected
 */
protected void checkNoReentry(final HttpServletRequest httpRequest) throws FilterNonReentrantException {
    Thread thread = Thread.currentThread();
    String threadName = thread.getName();
    String filterName = getClass().getName();
    if (thread.getName().indexOf(" been through " + filterName) != -1) {
        throw new FilterNonReentrantException("The request thread is attempting to reenter" + " filter "
                + filterName + ". URL: " + httpRequest.getRequestURL());
    }
    //Instrument thread name
    thread.setName(thread.getName() + " been through " + filterName);
    String newThreadName = thread.getName();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Thread name changed from " + threadName + " to " + newThreadName);
    }
}

From source file:org.apache.stratos.common.concurrent.locks.ReadWriteLock.java

/**
 * releases write lock//  www .  j  ava 2 s .c  om
 */
public void releaseWriteLock() {
    Thread currentThread = Thread.currentThread();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Releasing write lock: [lock-name] %s [thread-id] %d [thread-name] %s",
                getName(), currentThread.getId(), currentThread.getName()));
    }

    if (lock.writeLock().isHeldByCurrentThread()) {
        lock.writeLock().unlock();

        if (readWriteLockMonitorEnabled) {
            Map<LockType, LockMetadata> lockTypeLongMap = getLockTypeLongMap(currentThread.getId());
            lockTypeLongMap.remove(LockType.Write);
        }

        if (log.isDebugEnabled()) {
            log.debug(String.format("Write lock released: [lock-name] %s [thread-id] %d [thread-name] %s",
                    getName(), currentThread.getId(), currentThread.getName()));
        }
    } else {
        log.warn(String.format(
                "System warning! Trying to release a lock which has not been taken by the same thread: "
                        + "[lock-name] %s [thread-id] %d [thread-name] %s",
                getName(), currentThread.getId(), currentThread.getName()));
    }
}

From source file:pl.chilldev.commons.jsonrpc.daemon.AbstractApplication.java

/**
 * Stops listeners.//from   w  w w . j  a v  a2  s.  co  m
 */
@Override
public void stop() {
    this.logger.info("Stopping");

    // stop all threads
    this.threads.forEach(Listener::release);

    // wait for all threads
    for (Thread thread : this.threads) {
        try {
            // this is to make sure that thread don't hang on some I/O
            thread.interrupt();
            thread.join();
        } catch (InterruptedException error) {
            this.logger.error("Had to interrupt while waiting for thread \"{}\".", thread.getName(), error);
        }
    }
    // just to clean references
    this.threads.clear();
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.WebSocketTest.java

/**
 * {@inheritDoc}//from  w w  w. j a  v a2  s . com
 */
@After
@Override
public void releaseResources() {
    super.releaseResources();

    for (final Thread thread : Thread.getAllStackTraces().keySet()) {
        if (thread.getName().contains("WebSocket")) {
            try {
                // ok found one but let's wait a bit an start a second check before
                // pressing the panic button
                Thread.sleep(400);
            } catch (final InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    String lastFailing = null;
    for (final java.util.Map.Entry<Thread, StackTraceElement[]> entry : Thread.getAllStackTraces().entrySet()) {
        final Thread thread = entry.getKey();
        if (thread.getName().contains("WebSocket")) {
            lastFailing = thread.getName();
            System.err.println();
            System.err.println("WebSocket thread named '" + lastFailing + "' still running");
            final StackTraceElement[] traces = entry.getValue();
            for (int i = 0; i < traces.length; i++) {
                System.err.println(traces[i]);
            }
        }
    }

    assertNull("WebSocket thread named '" + lastFailing + "' still running", lastFailing);
}

From source file:org.apache.stratos.common.concurrent.locks.ReadWriteLock.java

/**
 * acquires write lock/*from  w w  w  . j  a  va  2s  .c  o  m*/
 */
public void acquireWriteLock() {
    Thread currentThread = Thread.currentThread();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Acquiring write lock: [lock-name] %s [thread-id] %d [thread-name] %s",
                getName(), currentThread.getId(), currentThread.getName()));
    }

    if (readWriteLockMonitorEnabled) {
        // Check whether the thread has already taken a read lock before requesting a write lock
        Map<LockType, LockMetadata> lockTypeLongMap = getLockTypeLongMap(currentThread.getId());
        if (lockTypeLongMap.containsKey(LockType.Read)) {
            String message = String.format(
                    "System error, cannot acquire a write lock while having a "
                            + "read lock on the same thread: [lock-name] %s [thread-id] %d [thread-name] %s",
                    getName(), currentThread.getId(), currentThread.getName());
            InvalidLockRequestedException exception = new InvalidLockRequestedException(message);
            log.error(exception);
            throw exception;
        }
    }

    lock.writeLock().lock();

    if (readWriteLockMonitorEnabled) {
        LockMetadata lockMetadata = new LockMetadata(getName(), LockType.Write, currentThread.getId(),
                currentThread.getName(), currentThread.getStackTrace(), System.currentTimeMillis());
        Map<LockType, LockMetadata> lockTypeLongMap = getLockTypeLongMap(currentThread.getId());
        lockTypeLongMap.put(lockMetadata.getLockType(), lockMetadata);
    }

    if (log.isDebugEnabled()) {
        log.debug(String.format("Write lock acquired: [lock-name] %s [thread-id] %d [thread-name] %s",
                getName(), currentThread.getId(), currentThread.getName()));
    }
}