リストを 2 つの方法で変更する必要があるプログラムを作成しています。この実装は完全に機能しますが、2 番目のスレッドがロックを取得できません。
Node head = new Node(new Object(), null);
public static ReentrantLock lock = new ReentrantLock();
...
boolean add(Object o){
lock.lock();
Node current = head;
Node previous = head.next;
if(head.next==null){
head.addNext(new Node(o,null));
return true;
}
while(!(current.next == null)){
current=current.next;
previous=previous.next;
}
current.addNext(new Node(o,null));
lock.unlock();
return true;
}
多分誰かがそれがなぜなのか知っていますか?