mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-13 11:09:10 +01:00
Add newCachedThreadPool to Utilities
Use newCachedThreadPool instead of getThreadPoolExecutor Utilities.getThreadPoolExecutor use a BlockingQueue which prevents the intended behaviour to increase the pool size to the max value. Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
f4775f89b0
commit
3308e35e8c
2 changed files with 10 additions and 3 deletions
|
@ -64,6 +64,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.SynchronousQueue;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -135,6 +136,12 @@ public class Utilities {
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ExecutorService newCachedThreadPool(int maximumPoolSize) {
|
||||||
|
return new ThreadPoolExecutor(0, maximumPoolSize,
|
||||||
|
60, TimeUnit.SECONDS,
|
||||||
|
new SynchronousQueue<>());
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("SameParameterValue")
|
@SuppressWarnings("SameParameterValue")
|
||||||
public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String name,
|
public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String name,
|
||||||
int corePoolSize,
|
int corePoolSize,
|
||||||
|
|
|
@ -60,7 +60,7 @@ import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ public class SeedNodeReportingService {
|
||||||
|
|
||||||
private Timer dataReportTimer;
|
private Timer dataReportTimer;
|
||||||
private final Timer heartBeatTimer;
|
private final Timer heartBeatTimer;
|
||||||
private final ThreadPoolExecutor executor;
|
private final ExecutorService executor;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SeedNodeReportingService(P2PService p2PService,
|
public SeedNodeReportingService(P2PService p2PService,
|
||||||
|
@ -123,7 +123,7 @@ public class SeedNodeReportingService {
|
||||||
this.maxConnections = maxConnections;
|
this.maxConnections = maxConnections;
|
||||||
this.seedNodeReportingServerUrl = seedNodeReportingServerUrl;
|
this.seedNodeReportingServerUrl = seedNodeReportingServerUrl;
|
||||||
|
|
||||||
executor = Utilities.getThreadPoolExecutor("SeedNodeReportingService", 2, 4, 30);
|
executor = Utilities.newCachedThreadPool(5);
|
||||||
httpClient = HttpClient.newHttpClient();
|
httpClient = HttpClient.newHttpClient();
|
||||||
|
|
||||||
heartBeatTimer = UserThread.runPeriodically(this::sendHeartBeat, HEART_BEAT_DELAY_SEC);
|
heartBeatTimer = UserThread.runPeriodically(this::sendHeartBeat, HEART_BEAT_DELAY_SEC);
|
||||||
|
|
Loading…
Add table
Reference in a new issue