public class MyClass {
public static void main(String args[]) {
Thread mainThread = Thread.currentThread();
System.out.println("Current thread: " + mainThread);
mainThread.setName("MyThread");
System.out.println("Current thread: " + mainThread);
try {
for (int i = 1; i <= 7; i++) {
System.out.println("i = " + i);
Thread.sleep(500);
}
}
catch (InterruptedException e) {
System.out.println("Exception: " + e);
}
}
}
/*
run:
Current thread: Thread[main,5,main]
Current thread: Thread[MyThread,5,main]
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
*/