forked from Qortal/qortal
Set peer connect to a dedicated thread pool for non-blocking I/O (Thanks to RAZ)
This commit is contained in:
parent
4b037ad13f
commit
0a44928e93
4
pom.xml
4
pom.xml
@ -16,7 +16,7 @@
|
||||
<ciyam-at.version>1.4.2</ciyam-at.version>
|
||||
<commons-net.version>3.8.0</commons-net.version>
|
||||
<commons-text.version>1.12.0</commons-text.version>
|
||||
<commons-io.version>2.17.0</commons-io.version>
|
||||
<commons-io.version>2.18.0</commons-io.version>
|
||||
<commons-compress.version>1.27.1</commons-compress.version>
|
||||
<commons-lang3.version>3.17.0</commons-lang3.version>
|
||||
<dagger.version>1.2.2</dagger.version>
|
||||
@ -28,7 +28,7 @@
|
||||
<homoglyph.version>1.2.1</homoglyph.version>
|
||||
<hsqldb.version>2.7.4</hsqldb.version>
|
||||
<icu4j.version>76.1</icu4j.version>
|
||||
<java-diff-utils.version>4.12</java-diff-utils.version>
|
||||
<java-diff-utils.version>4.15</java-diff-utils.version>
|
||||
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
|
||||
<jaxb-runtime.version>2.3.9</jaxb-runtime.version>
|
||||
<jersey.version>2.42</jersey.version>
|
||||
|
@ -146,6 +146,8 @@ public class Block {
|
||||
private final Account recipientAccount;
|
||||
private final AccountData recipientAccountData;
|
||||
|
||||
final BlockChain blockChain = BlockChain.getInstance();
|
||||
|
||||
ExpandedAccount(Repository repository, RewardShareData rewardShareData) throws DataException {
|
||||
this.rewardShareData = rewardShareData;
|
||||
this.sharePercent = this.rewardShareData.getSharePercent();
|
||||
@ -191,13 +193,12 @@ public class Block {
|
||||
if (accountLevel <= 0)
|
||||
return null; // level 0 isn't included in any share bins
|
||||
|
||||
if (blockHeight >= BlockChain.getInstance().getFixBatchRewardHeight()) {
|
||||
if (blockHeight >= blockChain.getFixBatchRewardHeight()) {
|
||||
if (!this.isMinterMember)
|
||||
return null; // not member of minter group isn't included in any share bins
|
||||
}
|
||||
|
||||
// Select the correct set of share bins based on block height
|
||||
final BlockChain blockChain = BlockChain.getInstance();
|
||||
final AccountLevelShareBin[] shareBinsByLevel = (blockHeight >= blockChain.getSharesByLevelV2Height()) ?
|
||||
blockChain.getShareBinsByAccountLevelV2() : blockChain.getShareBinsByAccountLevelV1();
|
||||
|
||||
|
@ -4,10 +4,15 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.network.Network;
|
||||
import org.qortal.network.Peer;
|
||||
import org.qortal.utils.DaemonThreadFactory;
|
||||
import org.qortal.utils.ExecuteProduceConsume.Task;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class PeerConnectTask implements Task {
|
||||
private static final Logger LOGGER = LogManager.getLogger(PeerConnectTask.class);
|
||||
private static final ExecutorService connectionExecutor = Executors.newCachedThreadPool(new DaemonThreadFactory(8));
|
||||
|
||||
private final Peer peer;
|
||||
private final String name;
|
||||
@ -24,6 +29,24 @@ public class PeerConnectTask implements Task {
|
||||
|
||||
@Override
|
||||
public void perform() throws InterruptedException {
|
||||
// Submit connection task to a dedicated thread pool for non-blocking I/O
|
||||
connectionExecutor.submit(() -> {
|
||||
try {
|
||||
connectPeerAsync(peer);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error("Connection attempt interrupted for peer {}", peer, e);
|
||||
Thread.currentThread().interrupt(); // Reset interrupt flag
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void connectPeerAsync(Peer peer) throws InterruptedException {
|
||||
// Perform peer connection in a separate thread to avoid blocking main task execution
|
||||
try {
|
||||
Network.getInstance().connectPeer(peer);
|
||||
LOGGER.trace("Successfully connected to peer {}", peer);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error connecting to peer {}", peer, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user