|
@@ -34,6 +34,7 @@ import org.slf4j.Logger;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.Executor;
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
@@ -97,6 +98,9 @@ public class GGame extends AbstractService {
|
|
|
/** 本服所有在线玩家 */
|
|
|
public static Map<String, GPlayer> onlinePlayers = new ConcurrentHashMap<>();
|
|
|
|
|
|
+ /** 异步业务执行器 */
|
|
|
+ protected Executor asyncExec;
|
|
|
+
|
|
|
public static GlobalInfoPO globalInfoPO = new GlobalInfoPO();
|
|
|
|
|
|
private static volatile GGame instance;
|
|
@@ -122,6 +126,28 @@ public class GGame extends AbstractService {
|
|
|
return lsDBHandler;
|
|
|
}
|
|
|
|
|
|
+ public void asyncExec(final Runnable command) {
|
|
|
+ if (command == null) {
|
|
|
+ logger.error("asyncExec command is null!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ asyncExec.execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ long lStartTime = System.currentTimeMillis();
|
|
|
+ command.run();
|
|
|
+ long lTimeUse = System.currentTimeMillis() - lStartTime;
|
|
|
+ if (lTimeUse > 1000) {
|
|
|
+ logger.info("asyncExec时间过长:{}, {}", lTimeUse, command);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("GGame asyncExec catch- ", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected void doStart() throws Throwable {
|
|
|
// 1.初始化Properties配置
|