Java Program on Main as a Thread

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Program 1

package dataflair;

public class TestMain 
{
    public static void main(String[] args) throws InterruptedException
    {
        System.out.println("Name of Main before change: "+ Thread.currentThread().getName());
          Thread.currentThread().setName("My Main Thread");
        System.out.println("Name of Main after change: "+ Thread.currentThread().getName());
        Thread T=new Thread();
         for(int i=1;i<=10;i++)    
         {    
             System.out.println(i);
             Thread.sleep(1000);
         }   
    }
    
}

 

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *