私は並行性の問題の宿題をしています。私は、多くのスレッドが特定の処理を行い、これらのスレッドがいつリソースにアクセスできるかを決定するメソッドを持っています。getWaitQueueLength throw IllegalArgumentException:所有者でない
だから私のクラスでは、このようなものになります。
public class Boss extends ReentrantLock implements Runnable {
Lock access = new ReentrantLock();
Condition canTakeOff = access.newCondition();
Condition canLand = access.newCondition();
public void accessToLanding(){
access.lock();
try{
if(getWaitQueueLength(canTakeOff) > 0){
canTakeOff.notifyAll();
} else if {
/* some other cases */
}
} catch (InterruptedException e){
e.printStackTrace();
} finally {
access.unlock();
}
}
public void run(){
accessToLanding();
}
/* Methods which are called by objects of a different class,
they are awaiting for the signal from accessToLanding.*/
}
を私はエラーを取得しています:
Exception in thread "Thread-0" java.lang.IllegalArgumentException: Not owner
at java.util.concurrent.locks.AbstractQueuedSynchronizer.getWaitQueueLength(AbstractQueuedSynchronizer.java:1789)
at java.util.concurrent.locks.ReentrantLock.getWaitQueueLength(ReentrantLock.java:720)
私はドキュメントをチェックしましたし、それは「与えられたときgetWaitQueueLengthはIllegalArgumentExceptionをスローすることを言います条件はこのロックに関連付けられていませんが、私が理解しているところでは、それは私のコードに関連付けられています。 誰かが私を助けることができますか?
私はそれを変更: 'access.getWaitQueueLength(canTakeOff)'それは方法getWaitQueueLengthを解決することはできません。 – bumbur
アクセス宣言を変更します。 Lockの代わりにReentrantLockを書きます。 – RubioRic
これで動作します。本当にありがとう、私は本当に感謝します! – bumbur