【发布时间】:2015-10-25 00:10:51
【问题描述】:
当我运行它时,我有这个下面的程序,它崩溃了。看起来在运行时有一些问题。我无法理解出了什么问题?谁能解释一下?
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();
}
这是错误消息,但为什么我收到 ArrayIndexOutOfBoundsException。谁能解释一下?
Exception in thread "Thread-5" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 244
【问题讨论】:
-
“崩溃”是什么意思?你在输出中有一些例外吗?您的 JVM 是否会因报告而崩溃?或者它只是停止了?
-
是的,我刚刚添加了错误消息.. 之前忘记添加了。
标签: java multithreading runnable