Skip to content

Instantly share code, notes, and snippets.

@codekaust
Created February 22, 2020 19:41
Show Gist options
  • Save codekaust/c339284f15fff7ec1a98ea098c2c1939 to your computer and use it in GitHub Desktop.
Save codekaust/c339284f15fff7ec1a98ea098c2c1939 to your computer and use it in GitHub Desktop.
Do not delete. Used in medium blog (Java Multi-Threading) under MDG.
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