Example usage for java.lang Thread getPriority

List of usage examples for java.lang Thread getPriority

Introduction

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

Prototype

public final int getPriority() 

Source Link

Document

Returns this thread's priority.

Usage

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    System.out.println("main Thread  Priority:" + t.getPriority());

    Thread t1 = new Thread();
    System.out.println("Thread(t1) Priority:" + t1.getPriority());

    t.setPriority(Thread.MAX_PRIORITY);
    System.out.println("main Thread  Priority:" + t.getPriority());

    Thread t2 = new Thread();
    System.out.println("Thread(t2) Priority:" + t2.getPriority());

    // Change thread t2 priority to minimum
    t2.setPriority(Thread.MIN_PRIORITY);
    System.out.println("Thread(t2) Priority:" + t2.getPriority());
}

From source file:GetPriority.java

public static void main(String[] args) {
    System.out.println(/*from   w  ww  . ja va 2  s  .  c o m*/
            "in main() - Thread.currentThread().getPriority()=" + Thread.currentThread().getPriority());

    System.out.println("in main() - Thread.currentThread().getName()=" + Thread.currentThread().getName());

    Thread threadA = new Thread(makeRunnable(), "threadA");
    threadA.start();

    try {
        Thread.sleep(3000);
    } catch (InterruptedException x) {
    }

    System.out.println("in main() - threadA.getPriority()=" + threadA.getPriority());
}

From source file:GetPriority.java

private static Runnable makeRunnable() {
    Runnable r = new Runnable() {
        public void run() {
            for (int i = 0; i < 5; i++) {
                Thread t = Thread.currentThread();
                System.out.println("in run() - priority=" + t.getPriority() + ", name=" + t.getName());

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException x) {
                    // ignore
                }//w  w w  . j  av a  2 s.  c  o  m
            }
        }
    };

    return r;
}

From source file:Main.java

public static String getThreadSignature() {
    Thread t = Thread.currentThread();
    long l = t.getId();
    String name = t.getName();//  w  ww .  jav a 2 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 String getThreadSignature() {
    Thread t = Thread.currentThread();
    long id = t.getId();
    String name = t.getName();/*from  w  w  w .  j  av a 2 s.  c o m*/
    long pri = t.getPriority();
    String gname = t.getThreadGroup().getName();
    return (name + ":(id)" + id + ":(priority)" + pri + ":(group)" + gname);
}

From source file:ThreadLister.java

private static void printThreadInfo(Thread t, String indent) {
    if (t == null)
        return;/*from   w w w .j a  v a  2  s .  c  o m*/
    System.out.println(indent + "Thread: " + t.getName() + "  Priority: " + t.getPriority()
            + (t.isDaemon() ? " Daemon" : "") + (t.isAlive() ? "" : " Not Alive"));
}

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;//from www.  j a va  2s. com
}

From source file:ThreadLister.java

/** Display information about a thread. */
private static void printThreadInfo(PrintWriter out, Thread t, String indent) {
    if (t == null)
        return;//from w  w  w  .ja  va 2 s. c o  m
    out.println(indent + "Thread: " + t.getName() + "  Priority: " + t.getPriority()
            + (t.isDaemon() ? " Daemon" : "") + (t.isAlive() ? "" : " Not Alive"));
}

From source file:Main.java

/**
 * Display information about a thread./*from   ww w .  j  a  va2 s.com*/
 */
private static void printThreadInfo(PrintWriter out, Thread t, String indent) {
    if (t == null) {
        return;
    }
    out.println(indent + "Thread: " + t.getName() + "  Priority: " + t.getPriority()
            + (t.isDaemon() ? " Daemon" : "") + (t.isAlive() ? "" : " Not Alive"));
}

From source file:Main.java

/** Collect info about a thread  */
private static void collectThreadInfo(final Thread t, final StringBuffer str, final String indent) {
    if (t == null) {
        return;//from  www .  ja v  a2s . co  m
    }
    str.append(indent).append("Thread: [").append(t.getName()).append("]  Priority: [").append(t.getPriority())
            .append(t.isDaemon() ? " Daemon" : "").append("] ").append(t.isAlive() ? "" : " Not Alive")
            .append(LINE_SEPARATOR);
}