Example usage for java.lang Thread getId

List of usage examples for java.lang Thread getId

Introduction

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

Prototype

public long getId() 

Source Link

Document

Returns the identifier of this Thread.

Usage

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    Main t1 = new Main(3);
    t1.createThread("Child 1");
    t1.createThread("Child 2");
    for (int i = 0; i <= 5; i++) {
        try {//from  w  w w.  j  av  a2  s  .c o m
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("The cirrent Thread is " + t.getName() + " and thread ID is " + t.getId());
    }
}

From source file:Main.java

public static long getThreadId() {

    Thread t = Thread.currentThread();
    return t.getId();
}

From source file:Main.java

public static String getThreadSignature() {
    Thread t = Thread.currentThread();
    long l = t.getId();
    String name = t.getName();/*from  w w  w.  jav a2  s.c  o  m*/
    long p = t.getPriority();
    String gname = t.getThreadGroup().getName();
    return (name + ":(id)" + l + ":(priority)" + p + ":(group)" + gname);
}

From source file:Main.java

public static long getCurrentThreadId() {
    Thread thread = Thread.currentThread();
    long l = thread.getId();
    ;/*from  w  w  w  . jav  a2  s  .  c  o  m*/
    return l;
}

From source file:Main.java

public static String getThreadSignature() {
    Thread t = Thread.currentThread();
    long id = t.getId();
    String name = t.getName();/*  ww  w .  jav a2 s.co  m*/
    long pri = t.getPriority();
    String gname = t.getThreadGroup().getName();
    return (name + ":(id)" + id + ":(priority)" + pri + ":(group)" + gname);
}

From source file:Main.java

public static String getThreadInfo(Thread thread) {
    String info = String.format("id:%s, Name:%s, State:%s , Status:%d", thread.getId(), thread.getName(),
            thread.getState(), thread.getPriority());
    return info;/*  w w  w.j  a va2 s .  c om*/
}

From source file:Main.java

public static Thread getThreadById(long threadID) {

    for (Thread thread : getAllThreads()) {
        if (thread.getId() == threadID)
            return thread;
    }//  w w  w .j  a  v a  2s.c  om

    return null;
}

From source file:Main.java

public static String dumpStack(Thread t) {
    StringBuilder sb = new StringBuilder();
    sb.append(t.getName() + "[" + t.getId() + "] - " + t.getState() + ":\n");
    for (StackTraceElement ste : t.getStackTrace()) {
        sb.append("\tat " + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":"
                + ste.getLineNumber() + ")\n");
    }//w w  w .j av  a  2  s . co  m
    return sb.toString();
}

From source file:Main.java

/**
 * Gets a thread by its assigned ID.  Internally, this method calls
 * getAllThreads() so be careful to only call this method once and cache
 * your result.//from  ww  w . j  ava2  s .co  m
 * @param id The thread ID
 * @return The thread with this ID or null if none were found
 */
static public Thread getThread(final long id) {
    final Thread[] threads = getAllThreads();
    for (Thread thread : threads)
        if (thread.getId() == id)
            return thread;
    return null;
}

From source file:ThreadTimer.java

public static ThreadTimer timerForThread(Thread t) {
    return new ThreadTimer(t.getId());
}