mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 19:11:59 -08: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<UUID, User> users = new ConcurrentHashMap<>();
|
||||||
private final ConcurrentHashMap<String, User> usersByName = 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();
|
private static final UserManager INSTANCE = new UserManager();
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ public class UserManager {
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
final User user = users.get(userId);
|
final User user = users.get(userId);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
CALL_EXECUTOR.execute(
|
USER_EXECUTOR.execute(
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
@ -212,7 +212,7 @@ public class UserManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateUserHistory() {
|
public void updateUserHistory() {
|
||||||
CALL_EXECUTOR.execute(new Runnable() {
|
USER_EXECUTOR.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (String updatedUser : UserStatsRepository.instance.updateUserStats()) {
|
for (String updatedUser : UserStatsRepository.instance.updateUserStats()) {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@
|
||||||
* The views and conclusions contained in the software and documentation are those of the
|
* 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
|
* authors and should not be interpreted as representing official policies, either expressed
|
||||||
* or implied, of BetaSteward_at_googlemail.com.
|
* or implied, of BetaSteward_at_googlemail.com.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mage.server.util;
|
package mage.server.util;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
@ -42,31 +41,37 @@ import java.util.concurrent.TimeUnit;
|
||||||
public class ThreadExecutor {
|
public class ThreadExecutor {
|
||||||
|
|
||||||
private static final ExecutorService callExecutor = Executors.newCachedThreadPool();
|
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 ExecutorService gameExecutor = Executors.newFixedThreadPool(ConfigSettings.getInstance().getMaxGameThreads());
|
||||||
private static final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(4);
|
private static final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(4);
|
||||||
private static final ScheduledExecutorService timeoutIdleExecutor = 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
|
* noxx: what the settings below do is setting the ability to keep OS
|
||||||
* If there is no new game created within this time period, the thread may be discarded.
|
* threads for new games for 60 seconds If there is no new game created
|
||||||
* But anyway if new game is created later, new OS/java thread will be created for it
|
* within this time period, the thread may be discarded. But anyway if new
|
||||||
* taking MaxGameThreads limit into account.
|
* 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 {
|
static {
|
||||||
((ThreadPoolExecutor)callExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
((ThreadPoolExecutor) callExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
((ThreadPoolExecutor)callExecutor).allowCoreThreadTimeOut(true);
|
((ThreadPoolExecutor) callExecutor).allowCoreThreadTimeOut(true);
|
||||||
((ThreadPoolExecutor)callExecutor).setThreadFactory(new XMageThreadFactory("CALL"));
|
((ThreadPoolExecutor) callExecutor).setThreadFactory(new XMageThreadFactory("CALL"));
|
||||||
((ThreadPoolExecutor)gameExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
((ThreadPoolExecutor) userExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
((ThreadPoolExecutor)gameExecutor).allowCoreThreadTimeOut(true);
|
((ThreadPoolExecutor) userExecutor).allowCoreThreadTimeOut(true);
|
||||||
((ThreadPoolExecutor)gameExecutor).setThreadFactory(new XMageThreadFactory("GAME"));
|
((ThreadPoolExecutor) userExecutor).setThreadFactory(new XMageThreadFactory("USER"));
|
||||||
((ThreadPoolExecutor)timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
((ThreadPoolExecutor) gameExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
((ThreadPoolExecutor)timeoutExecutor).allowCoreThreadTimeOut(true);
|
((ThreadPoolExecutor) gameExecutor).allowCoreThreadTimeOut(true);
|
||||||
((ThreadPoolExecutor)timeoutExecutor).setThreadFactory(new XMageThreadFactory("TIMEOUT"));
|
((ThreadPoolExecutor) gameExecutor).setThreadFactory(new XMageThreadFactory("GAME"));
|
||||||
((ThreadPoolExecutor)timeoutIdleExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
((ThreadPoolExecutor) timeoutExecutor).setKeepAliveTime(60, TimeUnit.SECONDS);
|
||||||
((ThreadPoolExecutor)timeoutIdleExecutor).allowCoreThreadTimeOut(true);
|
((ThreadPoolExecutor) timeoutExecutor).allowCoreThreadTimeOut(true);
|
||||||
((ThreadPoolExecutor)timeoutIdleExecutor).setThreadFactory(new XMageThreadFactory("TIMEOUT_IDLE"));
|
((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();
|
private static final ThreadExecutor INSTANCE = new ThreadExecutor();
|
||||||
|
|
@ -75,11 +80,12 @@ public class ThreadExecutor {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ThreadExecutor() {}
|
private ThreadExecutor() {
|
||||||
|
}
|
||||||
|
|
||||||
public int getActiveThreads(ExecutorService executerService) {
|
public int getActiveThreads(ExecutorService executerService) {
|
||||||
if (executerService instanceof ThreadPoolExecutor) {
|
if (executerService instanceof ThreadPoolExecutor) {
|
||||||
return ((ThreadPoolExecutor)executerService).getActiveCount();
|
return ((ThreadPoolExecutor) executerService).getActiveCount();
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -109,10 +115,12 @@ class XMageThreadFactory implements ThreadFactory {
|
||||||
XMageThreadFactory(String prefix) {
|
XMageThreadFactory(String prefix) {
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
Thread thread = new Thread(r);
|
Thread thread = new Thread(r);
|
||||||
thread.setName(prefix + " " + thread.getThreadGroup().getName() + "-" + thread.getId());
|
thread.setName(prefix + " " + thread.getThreadGroup().getName() + "-" + thread.getId());
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue