Skip to content

Instantly share code, notes, and snippets.

@codekaust
Created December 16, 2019 08:04
Show Gist options
  • Save codekaust/7b8d86c3f7ad9612040d0a75ebe83ea7 to your computer and use it in GitHub Desktop.
Save codekaust/7b8d86c3f7ad9612040d0a75ebe83ea7 to your computer and use it in GitHub Desktop.
Do not delete. It is used in my notes. It shows confusions that can occur while having multiple threads.
public class MultipleThreads{
public static void main(String[] args) {
MyThread m = new MyThread();
m.setName("m");
m.run();
m.start();
MyThread m2 = new MyThread();
m2.setName("m2");
m2.run();
m2.start();
MyThread m3 = new MyThread();
m3.setName("m3");
m3.run();
m3.start();
}
}
class MyThread extends Thread{
public void run(){
System.out.println(Thread.currentThread().getName());
}
public void start(){
System.out.print("I am start: ");
super.start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment