This is the code for my thread test.
class TestThread extends Thread {
@Override
public void run() {
while (true) {
System.out.println("Run thread "+this.getId());
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
In the main function, I set up 100 threads:
for (int i = 0; i < 100; i++) {
TestThread tt = new TestThread();
tt.run();
}
And this is the result I got
Run thread 8
Run thread 8
Run thread 8
Run thread 8
...
Why only thread 8 printed out? It seems that this is the only thread that is running. How can I make other threads work?