Example usage for java.lang Thread currentThread

List of usage examples for java.lang Thread currentThread

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static native Thread currentThread();

Source Link

Document

Returns a reference to the currently executing thread object.

Usage

From source file:MyThread.java

public static void main(String[] args) throws Exception {

    Thread thread = new MyThread();
    System.out.println("thread = " + thread.currentThread());
    thread.setDaemon(true);//w ww  .  ja  v a 2  s. c  o m

    // this will call run() method
    thread.start();
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");
    // set thread priority to 1
    t.setPriority(1);//  w ww  . j a va 2  s.  co  m

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);

    Thread.dumpStack();/*w w  w  .  ja v  a2 s  . c om*/
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    System.out.println("Thread = " + t);

    t.setName("java2s.com thread");

    System.out.println("Thread after changing name = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");
    // set thread priority to 1
    t.setPriority(Thread.NORM_PRIORITY);

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");
    // set thread priority to 1
    t.setPriority(Thread.MIN_PRIORITY);

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
}

From source file:Main.java

public static void main(String[] args) {

    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");
    // set thread priority to 1
    t.setPriority(Thread.MAX_PRIORITY);

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);
}

From source file:Main.java

public static void main(String[] args) {
    Thread t1 = Thread.currentThread();

    ThreadGroup tg1 = t1.getThreadGroup();

    System.out.println("Current thread's  name:  " + t1.getName());
    System.out.println("Current thread's  group  name:  " + tg1.getName());

    Thread t2 = new Thread("my  new thread");

    ThreadGroup tg2 = t2.getThreadGroup();
    System.out.println("New  thread's name:  " + t2.getName());
    System.out.println("New  thread's  group  name:  " + tg2.getName());
}

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:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    t.setName("java2s.com thread");

    System.out.println("Thread = " + t);

    int count = Thread.activeCount();
    System.out.println("currently active threads = " + count);

    Thread th[] = new Thread[count];
    Thread.enumerate(th);/*from  w w  w .  j  a v a 2 s.  c  o m*/

    for (int i = 0; i < count; i++) {
        System.out.println(i + ": " + th[i]);
    }
}