make server pings not block each other
This commit is contained in:
@@ -19,6 +19,8 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class QueueManagerImpl implements QueueManager {
|
||||
@@ -474,9 +476,14 @@ public class QueueManagerImpl implements QueueManager {
|
||||
|
||||
@Override
|
||||
public void updateServers() {
|
||||
ExecutorService pool = main.getTaskManager().getServersUpdateExecutor();
|
||||
if (pool instanceof ThreadPoolExecutor && main.getConfig().getBoolean("pinger-debug")) {
|
||||
main.getLogger().info("[pinger] Server update thread pool has "
|
||||
+((ThreadPoolExecutor) pool).getActiveCount()+" threads");
|
||||
}
|
||||
try {
|
||||
for(QueueServer server : servers) {
|
||||
server.updatePing();
|
||||
pool.submit(server::updatePing);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -2,10 +2,7 @@ package us.ajg0702.queue.common;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class TaskManager {
|
||||
|
||||
@@ -13,6 +10,8 @@ public class TaskManager {
|
||||
final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
final ScheduledExecutorService updateExecutor = Executors.newScheduledThreadPool(1);
|
||||
|
||||
final ExecutorService serversUpdateExecutor = Executors.newCachedThreadPool();
|
||||
|
||||
final QueueMain main;
|
||||
public TaskManager(QueueMain main) {
|
||||
this.main = main;
|
||||
@@ -21,6 +20,11 @@ public class TaskManager {
|
||||
public void shutdown() {
|
||||
executor.shutdown();
|
||||
updateExecutor.shutdown();
|
||||
serversUpdateExecutor.shutdown();
|
||||
}
|
||||
|
||||
public ExecutorService getServersUpdateExecutor() {
|
||||
return serversUpdateExecutor;
|
||||
}
|
||||
|
||||
public String taskStatus() {
|
||||
@@ -52,7 +56,7 @@ public class TaskManager {
|
||||
updateTask = scheduleAtFixedRate(updateExecutor,
|
||||
main.getQueueManager()::updateServers,
|
||||
500L,
|
||||
(long) (Math.max(main.getTimeBetweenPlayers()/2, 2)*1000L),
|
||||
(long) (Math.max(main.getTimeBetweenPlayers()/2, 1)*1000L),
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user