public void handleLinkWeights(LinkWeightMessage m) { //Calculate shortest paths when all edges and peers discovered.
peerLock.lock();
int size = m.weights.length; //All lists should be the same size
for (int x = 0; x < size; ++x){
NodeMessage a = m.anodes.get(x),
b = m.bnodes.get(x);
if (hasPeer(a.address, a.port)) {
// ...
}
}
peerLock.unlock();
//TODO
}
private boolean hasPeer(String address, int port) {
peerLock.lock();
peerLock.unlock();
}
如果我运行上面的代码,我会失去我的锁吗?(代码不完整。)
peerLock
是一个ReentrantLock
其余的可以从上下文中推断出来。