Created
February 22, 2020 19:41
-
-
Save codekaust/c339284f15fff7ec1a98ea098c2c1939 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 ThreadUsingRunnableInterface{ | |
public static void main(String[] args) { | |
//without name | |
Thread t1 = new Thread(new MyRunnable()); | |
t1.start(); | |
//with name | |
Thread t2 = new Thread(new MyRunnable(), "Example_thread"); | |
t2.start(); | |
} | |
} | |
class MyRunnable implements Runnable{ | |
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