Download Norton Internet Security 2012 3User [Download] saving really big 58%. The complete security for your PC. The best if you are an Internet User. It is found to be the best Internet Security Suite. You may also have an idea and heard about it.
Main thread runs automatically when your program starts.
Output :
-------------------------------------------------------------
My old name is main
My new name is My Main Thread
My Main Thread: 5
My Main Thread: 4
My Main Thread: 3
My Main Thread: 2
My Main Thread: 1
Main thread runs automatically when your program starts.
class MainThread-------------------------------------------------------------
{
public static void main(String args[])
{
// Get current thread's object
Thread mainThread=Thread.currentThread();
// Get the name of the main thread
String oldName=mainThread.getName();
// Print the default name
System.out.println("My old name is "+oldName);
// Set a name to the main thread
mainThread.setName("My Main Thread");
// Print the new name
System.out.println("My new name is "+mainThread.getName());
// Start the loop
try
{
for(int i=5;i>=1;i--)
{
System.out.println(mainThread.getName()+": "+i);
Thread.sleep(1000);
}
}catch(InterruptedException e){
System.out.println("Main thread interrupted.");
}
}
}
Output :
-------------------------------------------------------------
My old name is main
My new name is My Main Thread
My Main Thread: 5
My Main Thread: 4
My Main Thread: 3
My Main Thread: 2
My Main Thread: 1