I'm new to threads in java and I'm trying to test how it works. Unfortunately, things goes as I'm not expecting. threads seems to execute in a not-parallel way. I've tried the sleep function but things stay the same.
The string "aa" does not printed until the thread dies !!! What should I do?
class ThreadTest1 extends Thread {
public void start() {
for (int i=0; i<=100; i+=2) {
System.out.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
class Test {
public static void main(String[] args) throws InterruptedException {
for (int i=0; i<50; i++) {
Thread t1=new ThreadTest1();
t1.start();
System.out.println("aa");
}
}
}