Why output not the "1,2,3,4,5" ? Maybe multiple threads gets instance variable at the same time ? or it's about outer class variable is accessed from inner class methods ?
public class Test {
int i;
public static void main(String[] args) {
Test t = new Test();
for (t.i = 1; t.i <= 5; t.i++) {
new Thread(new Runnable() {
@Override
public void run() {
System.out.println(t.i);
}
}).start();
}
}
}