Created
February 22, 2020 19:38
-
-
Save codekaust/fd9ed2157ca9e68562028f8590176d9f to your computer and use it in GitHub Desktop.
Do not delete. Used in medium blog (Java Multi-Threading) under MDG.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThreadUsingThreadClass{ | |
public static void main(String[] args) { | |
System.out.println("Main thread name: "+ Thread.currentThread().getName()); | |
Thread t = new Thread(/*Thread name*/"Thread 1"); | |
t.start(); | |
// "Thread" constructor with thread_name parameter not "MyThread" | |
// MyThread mt = new MyThread("Example_Thread"); | |
// mt.start(); | |
MyThread mt = new MyThread(); | |
mt.start(); | |
MyThread2 mt2 = new MyThread2("Example_Thread2"); | |
mt2.start(); | |
} | |
} | |
class MyThread extends Thread{ | |
public void run(){ | |
System.out.println("Thread name: "+ Thread.currentThread().getName()); | |
System.out.println("Thread id: "+ Thread.currentThread().getId()); | |
} | |
} | |
class MyThread2 extends Thread{ | |
public MyThread2(String thread_name){ | |
super(thread_name); | |
} | |
public void run(){ | |
System.out.println("Thread name: "+ Thread.currentThread().getName()); | |
System.out.println("Thread id: "+ Thread.currentThread().getId()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment