Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main_Thread
- {
- 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); //print number with interval of 1 sec.
- Thread.sleep(1000); //Thread is going to sleep for 1 sec.
- }
- }
- catch (InterruptedException e)
- {
- System.out.println("Main thread interrupted");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement