Adv Java Program : Write a java program to display name of currently executing Thread in multithreading.

Write a java program to display name of currently executing Thread in multithreading.


TestMultiNaming.java



 import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;


public class TestMultiNaming extends Thread {


  public void run(){

   System.out.println("running...");

  }

public static void main(String args[]){

  TestMultiNaming thread1=new TestMultiNaming();

  TestMultiNaming thread2=new TestMultiNaming();

  System.out.println("Name of t1:"+thread1.getName());

  System.out.println("Name of t2:"+thread2.getName());

 

  thread1.start();

  thread2.start();


  thread1.setName("1st");

  System.out.println("After changing name of thread1:"+thread1.getName());

thread2.setName("2nd");

System.out.println("After changing name of thread2:"+thread2.getName());

}


}


Post a Comment

0 Comments