Clean up some possible thread safety issues.
This commit is contained in:
@ -511,7 +511,7 @@ public class PeerCoordinator implements PeerListener
|
||||
{
|
||||
// Unchoke some random other peer
|
||||
unchokePeer();
|
||||
|
||||
synchronized(wantedPieces) {
|
||||
// Don't count disconnected peers for the rarest-first calculations
|
||||
for(Iterator iter = wantedPieces.iterator(); iter.hasNext(); ) {
|
||||
Piece piece = (Piece)iter.next();
|
||||
@ -519,6 +519,7 @@ public class PeerCoordinator implements PeerListener
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (listener != null)
|
||||
listener.peerChange(this, peer);
|
||||
|
@ -2,6 +2,7 @@ package org.klomp.snark;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Collections;
|
||||
|
||||
public class Piece implements Comparable {
|
||||
|
||||
@ -11,7 +12,7 @@ public class Piece implements Comparable {
|
||||
|
||||
public Piece(int id) {
|
||||
this.id = id;
|
||||
this.peers = new HashSet();
|
||||
this.peers = Collections.synchronizedSet(new HashSet());
|
||||
this.requested = false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user