I have this below program when I run it, it crashes. Looks like there is some problem at runtime. I am not able to understand what's wrong? Can anyone provide any explanation?
public static void main(String[] args) {
final ArrayList<Object> holder = new ArrayList<>();
final Runnable runnable = new Runnable() {
public void run() {
for (int i = 1; i <= 1000000; i++) {
holder.add(new Object());
}
}
};
new Thread(runnable).start();
new Thread(runnable).start();
new Thread(runnable).start();
}
Here is error message but why I am getting ArrayIndexOutOfBoundsException
. Can anyone provide explanation?
Exception in thread "Thread-5" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 244