mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
* Some minor changes.
This commit is contained in:
parent
f0206537c1
commit
450d850ab4
2 changed files with 39 additions and 31 deletions
|
@ -59,7 +59,7 @@ public class UserManager {
|
|||
private final ConcurrentHashMap<UUID, User> users = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<String, User> usersByName = new ConcurrentHashMap<>();
|
||||
|
||||
private static final ExecutorService CALL_EXECUTOR = ThreadExecutor.getInstance().getCallExecutor();
|
||||
private static final ExecutorService USER_EXECUTOR = ThreadExecutor.getInstance().getCallExecutor();
|
||||
|
||||
private static final UserManager INSTANCE = new UserManager();
|
||||
|
||||
|
@ -136,7 +136,7 @@ public class UserManager {
|
|||
if (userId != null) {
|
||||
final User user = users.get(userId);
|
||||
if (user != null) {
|
||||
CALL_EXECUTOR.execute(
|
||||
USER_EXECUTOR.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -212,7 +212,7 @@ public class UserManager {
|
|||
}
|
||||
|
||||
public void updateUserHistory() {
|
||||
CALL_EXECUTOR.execute(new Runnable() {
|
||||
USER_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (String updatedUser : UserStatsRepository.instance.updateUserStats()) {
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
*/
|
||||
package mage.server.util;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -42,31 +41,37 @@ import java.util.concurrent.TimeUnit;
|
|||
public class ThreadExecutor {
|
||||
|
||||
private static final ExecutorService callExecutor = Executors.newCachedThreadPool();
|
||||
private static final ExecutorService userExecutor = Executors.newCachedThreadPool();
|
||||
private static final ExecutorService gameExecutor = Executors.newFixedThreadPool(ConfigSettings.getInstance().getMaxGameThreads());
|
||||
private static final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(4);
|
||||
private static final ScheduledExecutorService timeoutIdleExecutor = Executors.newScheduledThreadPool(4);
|
||||
|
||||
/**
|
||||
* noxx: what the settings below do is setting the ability to keep OS threads for new games for 60 seconds
|
||||
* If there is no new game created within this time period, the thread may be discarded.
|
||||
* But anyway if new game is created later, new OS/java thread will be created for it
|
||||
* taking MaxGameThreads limit into account.
|
||||
* noxx: what the settings below do is setting the ability to keep OS
|
||||
* threads for new games for 60 seconds If there is no new game created
|
||||
* within this time period, the thread may be discarded. But anyway if new
|
||||
* game is created later, new OS/java thread will be created for it taking
|
||||
* MaxGameThreads limit into account.
|
||||
*
|
||||
* This all is done for performance reasons as creating new OS threads is resource consuming process.
|
||||
* This all is done for performance reasons as creating new OS threads is
|
||||
* resource consuming process.
|
||||
*/
|
||||
static {
|
||||
((ThreadPoolExecutor)callExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor)callExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor)callExecutor).setThreadFactory(new XMageThreadFactory("CALL"));
|
||||
((ThreadPoolExecutor)gameExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor)gameExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor)gameExecutor).setThreadFactory(new XMageThreadFactory("GAME"));
|
||||
((ThreadPoolExecutor)timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor)timeoutExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor)timeoutExecutor).setThreadFactory(new XMageThreadFactory("TIMEOUT"));
|
||||
((ThreadPoolExecutor)timeoutIdleExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor)timeoutIdleExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor)timeoutIdleExecutor).setThreadFactory(new XMageThreadFactory("TIMEOUT_IDLE"));
|
||||
((ThreadPoolExecutor) callExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) callExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) callExecutor).setThreadFactory(new XMageThreadFactory("CALL"));
|
||||
((ThreadPoolExecutor) userExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) userExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) userExecutor).setThreadFactory(new XMageThreadFactory("USER"));
|
||||
((ThreadPoolExecutor) gameExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) gameExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) gameExecutor).setThreadFactory(new XMageThreadFactory("GAME"));
|
||||
((ThreadPoolExecutor) timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) timeoutExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) timeoutExecutor).setThreadFactory(new XMageThreadFactory("TIMEOUT"));
|
||||
((ThreadPoolExecutor) timeoutIdleExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||
((ThreadPoolExecutor) timeoutIdleExecutor).allowCoreThreadTimeOut(true);
|
||||
((ThreadPoolExecutor) timeoutIdleExecutor).setThreadFactory(new XMageThreadFactory("TIMEOUT_IDLE"));
|
||||
}
|
||||
|
||||
private static final ThreadExecutor INSTANCE = new ThreadExecutor();
|
||||
|
@ -75,19 +80,20 @@ public class ThreadExecutor {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
private ThreadExecutor() {}
|
||||
private ThreadExecutor() {
|
||||
}
|
||||
|
||||
public int getActiveThreads(ExecutorService executerService) {
|
||||
if (executerService instanceof ThreadPoolExecutor) {
|
||||
return ((ThreadPoolExecutor)executerService).getActiveCount();
|
||||
return ((ThreadPoolExecutor) executerService).getActiveCount();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public ExecutorService getCallExecutor() {
|
||||
return callExecutor;
|
||||
}
|
||||
|
||||
|
||||
public ExecutorService getGameExecutor() {
|
||||
return gameExecutor;
|
||||
}
|
||||
|
@ -99,20 +105,22 @@ public class ThreadExecutor {
|
|||
public ScheduledExecutorService getTimeoutIdleExecutor() {
|
||||
return timeoutIdleExecutor;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class XMageThreadFactory implements ThreadFactory {
|
||||
|
||||
|
||||
private final String prefix;
|
||||
|
||||
|
||||
XMageThreadFactory(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread thread = new Thread(r);
|
||||
thread.setName(prefix + " " + thread.getThreadGroup().getName() + "-" + thread.getId());
|
||||
return thread;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue