我得到这个异常,但我不明白为什么。embeddedStateException对嵌套锁
public Test() {
globalLock = new ReentrantLock();
condition = globalLock.newCondition();
}
public void increaseRow(Integer row) {
matrixLock.lock();
try {
while (countIncreasingColumn > 0)
condition.await();
countIncreasingRow++;
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
condition.notifyAll();
matrixLock.unlock();
synchronized (rows.get(row)) {
for (int j = 0; j < column; j++)
matrix[row][j] += 1;
countIncreasingRow--;
}
}
}
线程类:
public void run() {
while (true) {
test.function(new Random().nextInt(10));
}
}
堆栈跟踪:
Exception in thread "Thread-0" waiting thread for test 18
java.lang.IllegalMonitorStateException
at java.lang.Object.notifyAll(Native Method)
我是在notifyAll()
越来越thie例外。执行global.lock()
块的线程是所有者,那么为什么我得到这个?
这是什么神秘的例外?我们猜测吗?提供完整的堆栈跟踪。 – 2014-11-01 13:14:50
@BoristheSpider等一下。 – OiRc 2014-11-01 13:15:54
@BoristheSpider更新了 – OiRc 2014-11-01 13:19:02