Controlling the main Thread. : Thread Properties « Thread « Java Tutorial






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

    System.out.println("Current thread: " + t);

    t.setName("My Thread");
    System.out.println("After name change: " + t);

    try {
      for (int n = 5; n > 0; n--) {
        System.out.println(n);
        Thread.sleep(1000);
      }
    } catch (InterruptedException e) {
      System.out.println("Main thread interrupted");
    }
  }
}








10.2.Thread Properties
10.2.1.Controlling the main Thread.
10.2.2.Get current thread