https://www.youtube.com/watch?v=i_YcGps9Zqg&list=UUhwKlOVR041tngjerWxVccw
DisplayNumberThread.java
/* * public long getId() * * Returns the identifier of this Thread. The thread ID * is a positive long number generated when this thread * was created. The thread ID is unique and remains * unchanged during its lifetime. When a thread is * terminated, this thread ID may be reused. * * Returns: this thread's ID. */ class DisplayNumberThread extends Thread { public void run() { System.out.println("id = " + this.getId() + ", Name = " + this.getName()); } public static void main(String args[]) { DisplayNumberThread dnt1 = new DisplayNumberThread(); DisplayNumberThread dnt2 = new DisplayNumberThread(); DisplayNumberThread dnt3 = new DisplayNumberThread(); dnt1.start(); dnt2.start(); dnt3.start(); } }Output
id = 11, Name = Thread-1 id = 12, Name = Thread-2 id = 10, Name = Thread-0Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/Thread_Id_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/Thread_Id_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/ae6d3e57a6dd46b70df1238cfac12598c07fe0fb/BasicJava/Thread_Id_App/?at=master
See also:
No comments:
Post a Comment