I'm required to use multithreading for a project in my programming class so to practice and see how it works I used the code which was presented in the class. However, when I run the code all threads have the same ID, is this because of my system or does it has another reason?
This is the code:
MyThread.java:
public class MyThread implements Runnable {
public void run() {
try{
System.out.println("Thread id: " + Thread.currentThread().getId());
for(int i = 0; i <= 10; i++){
System.out.println(i);
}
}
catch (Exception e){
System.out.println(e.getCause().toString());
return;
}
}
}
App.java:
public class App {
public static void main(String[] args) {
MyThread [] threads = new MyThread[3];
for(int i = 0; i < 3; i++){
threads[i] = new MyThread();
}
for(int i = 0; i < 3; i++){
threads[i].run();
}
}
}