/* Java 2: The Complete Reference * by H.Schildt and P.Naughton * Chapter 11: Multithreaded Programming */ // Controlling the main Thread. /* public static Thread currentThread() Returns a reference to the currently executing thread object. public String toString() Returns a string representation of this thread, including the thread's name, priority, and thread group. Overrides: toString in class Object */ class CurrentThreadDemo { public static void main(String args[]) { Thread t = Thread.currentThread(); System.out.println("Current thread: " + t); // change the name of the thread 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"); } } }