mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 17:26:28 +01:00
Missing synchronization for iterations.
(over synchronizedMap/synchronizedSet)
This commit is contained in:
parent
831f2d582f
commit
4d58ea5111
1 changed files with 16 additions and 12 deletions
|
@ -304,7 +304,9 @@ public class PeerGroup {
|
||||||
*/
|
*/
|
||||||
public synchronized List<Peer> getConnectedPeers() {
|
public synchronized List<Peer> getConnectedPeers() {
|
||||||
ArrayList<Peer> result = new ArrayList<Peer>(peers.size());
|
ArrayList<Peer> result = new ArrayList<Peer>(peers.size());
|
||||||
|
synchronized (peers) {
|
||||||
result.addAll(peers);
|
result.addAll(peers);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,6 +368,7 @@ public class PeerGroup {
|
||||||
FutureTask<Transaction> future = new FutureTask<Transaction>(new Runnable() {
|
FutureTask<Transaction> future = new FutureTask<Transaction>(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
// This is run with the peer group already locked.
|
// This is run with the peer group already locked.
|
||||||
|
synchronized (peers) {
|
||||||
for (Peer peer : peers) {
|
for (Peer peer : peers) {
|
||||||
try {
|
try {
|
||||||
log.info("{}: Sending transaction {}", peer.getAddress(), tx.getHashAsString());
|
log.info("{}: Sending transaction {}", peer.getAddress(), tx.getHashAsString());
|
||||||
|
@ -375,6 +378,7 @@ public class PeerGroup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, tx);
|
}, tx);
|
||||||
peerGroupThread.addTask(future);
|
peerGroupThread.addTask(future);
|
||||||
return future;
|
return future;
|
||||||
|
@ -433,10 +437,8 @@ public class PeerGroup {
|
||||||
* {@link PeerEventListener} and use the onPeerConnected/onPeerDisconnected methods.
|
* {@link PeerEventListener} and use the onPeerConnected/onPeerDisconnected methods.
|
||||||
*/
|
*/
|
||||||
public synchronized int numConnectedPeers() {
|
public synchronized int numConnectedPeers() {
|
||||||
synchronized (peers) {
|
|
||||||
return peers.size();
|
return peers.size();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized boolean isRunning() {
|
public synchronized boolean isRunning() {
|
||||||
return running;
|
return running;
|
||||||
|
@ -500,9 +502,11 @@ public class PeerGroup {
|
||||||
synchronized (PeerGroup.this) {
|
synchronized (PeerGroup.this) {
|
||||||
running = false;
|
running = false;
|
||||||
shutdownPeerDiscovery();
|
shutdownPeerDiscovery();
|
||||||
|
synchronized (channelFutures.values()) {
|
||||||
for (ChannelFuture future : channelFutures.values()) {
|
for (ChannelFuture future : channelFutures.values()) {
|
||||||
future.getChannel().close();
|
future.getChannel().close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bootstrap.releaseExternalResources();
|
bootstrap.releaseExternalResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue