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.ilscipio.scipio.common.FileListener.java

public static Thread getThreadByName(String threadName) {
    for (Thread t : Thread.getAllStackTraces().keySet()) {
        if (t.getName().equals(threadName))
            return t;
    }/* w ww .j a  v  a 2s  . c  om*/
    return null;
}

From source file:Main.java

public static void startThreadStatusTimer(final Thread t1, int ms) {
    new Timer().schedule(new TimerTask() {
        @Override/*  w  ww  . java2s  .  c  o m*/
        public void run() {
            System.out.println("\t\t\t\t\t\t\t\t\t\tThread(" + t1.getName() + ") state - " + t1.getState());
        }
    }, 0, ms);
}

From source file:Main.java

/**
 * Get the thread info for the thread with the given name.
 * A null is returned if no such thread info is found.
 * If more than one thread has the same name, the thread
 * info for the first one found is returned.
 *
 * @param   name   the thread name to search for
 * @return      the thread info, or null if not found
 * @throws   NullPointerException//from  w ww.ja v a 2s . c  om
 *          if the name is null
 */
public static ThreadInfo getThreadInfo(final String name) {
    if (name == null)
        throw new NullPointerException("Null name");

    final Thread[] threads = getAllThreads();
    for (Thread thread : threads)
        if (thread.getName().equals(name))
            return getThreadInfo(thread.getId());
    return null;
}

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

/**
 * Helper function: print the threads//from  w ww  .j a va2s.c  o m
 */
public static void printThreads() {
    Set<Thread> threads = Thread.getAllStackTraces().keySet();
    System.out.println("name; state; isDameon; isAlive; isInterrupted");
    for (Thread t : threads) {
        System.out.println(t.getName() + ";" + t.getState() + ";" + t.isDaemon() + ";" + t.isAlive() + ";"
                + t.isInterrupted());
    }
}

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

/**
 * Sets an uncaught exception handler. This will make the process exit with
 * exit code 1 if a thread exits due to an uncaught exception.
 *//*  w  w  w.j  a va 2s . c  o m*/
public static void makeProcessExitOnUncaughtException(final Log log) {
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread t, Throwable e) {
            log.error("UNCAUGHT: Thread " + t.getName() + " got an uncaught exception", e);
            System.exit(1);
        }
    });
}

From source file:Main.java

/**
 * Get the thread with the given name.  A null is returned
 * if no such thread is found.  If more than one thread has
 * the same name, the first one found is returned.
 *
 * @param   name   the thread name to search for
 * @return      the thread, or null if not found
 * @throws   NullPointerException/*from www .  j  a  v  a 2  s . com*/
 *          if the name is null
 */
public static Thread getThread(final String name) {
    if (name == null)
        throw new NullPointerException("Null name");
    final Thread[] threads = getAllThreads();
    for (Thread thread : threads)
        if (thread.getName().equals(name))
            return thread;
    return null;
}

From source file:Main.java

/**
 * Get the thread with the given name. A null is returned if no such thread
 * is found. If more than one thread has the same name, the first one found
 * is returned.//w  w  w .j  a v  a 2  s.  c  om
 * 
 * @param name
 *        the thread name to search for
 * @return the thread, or null if not found
 * @throws NullPointerException
 *         if the name is null
 */
public static Thread getThread(final String name) {
    if (name == null) {
        throw new NullPointerException("Null name");
    }
    final Thread[] threads = getAllThreads();
    for (Thread thread : threads) {
        if (thread.getName().equals(name))
            return thread;
    }
    return null;
}

From source file:Main.java

/**
 * Get the thread info for the thread with the given name. A null is
 * returned if no such thread info is found. If more than one thread has the
 * same name, the thread info for the first one found is returned.
 * //from w  w w  .j a  v a2s .  c o  m
 * @param name
 *        the thread name to search for
 * @return the thread info, or null if not found
 * @throws NullPointerException
 *         if the name is null
 */
public static ThreadInfo getThreadInfo(final String name) {
    if (name == null) {
        throw new NullPointerException("Null name");
    }

    final Thread[] threads = getAllThreads();
    for (Thread thread : threads) {
        if (thread.getName().equals(name)) {
            return getThreadInfo(thread.getId());
        }
    }
    return null;
}

From source file:org.apache.hadoop.hbase.master.assignment.TestRegionStates.java

@BeforeClass
public static void setUp() throws Exception {
    threadPool = Threads.getBoundedCachedThreadPool(32, 60L, TimeUnit.SECONDS,
            Threads.newDaemonThreadFactory("ProcedureDispatcher", new UncaughtExceptionHandler() {
                @Override/*from  w  w  w.  j av  a 2 s.c om*/
                public void uncaughtException(Thread t, Throwable e) {
                    LOG.warn("Failed thread " + t.getName(), e);
                }
            }));
    executorService = new ExecutorCompletionService(threadPool);
}

From source file:edu.illinois.ncsa.springdata.Transaction.java

public static String getAllTransactions() {
    StringBuilder sb = new StringBuilder();

    StackTraceElement[] elems = new Exception().getStackTrace();
    for (int j = 0; j < elems.length; j++) {
        if (!elems[j].toString().startsWith("edu.illinois.ncsa.springdata.Transaction")) {
            sb.append(String.format("Called from %s\n", elems[j].toString()));
            break;
        }/*from  ww  w .j  a v a  2s.c  om*/
    }

    for (Thread thr : transactions.keySet()) {
        sb.append(String.format("%s\n", thr.getName()));
        getTransaction(sb, thr);
    }
    return sb.toString();
}