I am learning about Thread in Java. I was tring to fetch which thread is running. But, I am not able to understand the order of the output.
Following is my code
public class practice extends Thread {
public void run(){
for(int i=1;i<4;i++){
System.out.println(i);
System.out.println(Thread.currentThread().getName());
}
}
public static void main(String[] args) {
practice t1=new practice();
practice t2=new practice();
practice t3=new practice();
t1.start();
t2.start();
t3.start();
}
}
Output:
1
1
1
Thread-1
2
Thread-1
3
Thread-1
Thread-0
2
Thread-0
3
Thread-0
Thread-2
2
Thread-2
3
Thread-2
Can anyone help me out in understand the order of output. Thanks in advance.