跨服排行榜逻辑改为线程池调用
parent
6368008837
commit
c43b9eb56d
|
|
@ -76,10 +76,9 @@ public class UserManager {
|
|||
* 这个方法可能由定时任务或某种监控服务调用
|
||||
*/
|
||||
public static void checkOffline(){
|
||||
Thread.currentThread().setName("user_cache_clean");
|
||||
long now = TimeUtils.now();
|
||||
LOGGER.info("玩家缓存清理开始,当前时间:{},当前线程名称:{}",TimeUtils.getTimeStamp2(now),Thread.currentThread().getName());
|
||||
List<User> usersToRemove = new ArrayList<>();
|
||||
|
||||
try {
|
||||
synchronized (userMap) { // 同步userMap以防止并发修改
|
||||
for (User user : userMap.values()) {
|
||||
|
|
@ -93,7 +92,6 @@ public class UserManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 移除过期的用户
|
||||
for (User user : usersToRemove) {
|
||||
removeUser(user.getId());
|
||||
|
|
@ -102,7 +100,7 @@ public class UserManager {
|
|||
LOGGER.error("Exception in offline cleanup logic", e); // 记录完整的异常信息
|
||||
}
|
||||
|
||||
LOGGER.info("checkOffline last_count={}, consumer_time:{}ms", getUserMapSize(), TimeUtils.now()-now);
|
||||
LOGGER.info("玩家缓存清理开始 剩余数量={}, 消耗时间:{}ms", getUserMapSize(), TimeUtils.now()-now);
|
||||
}
|
||||
|
||||
public static User userLogin(int uid,String openId,String channel,int pid,int gid,String platform,String ip,String channle_id,String bundle_id,String ccId,String pack_Id) throws Exception {
|
||||
|
|
|
|||
|
|
@ -38,45 +38,48 @@ public class CrossRankManager {
|
|||
/**
|
||||
* 跨服排行处理
|
||||
*/
|
||||
public void crossRankHandle(){
|
||||
public static void crossRankHandle(){
|
||||
// 时间验证
|
||||
if (isTime()){
|
||||
// 全部排行遍历
|
||||
for (RankEnum value : RankEnum.values()) {
|
||||
int type = value.getType();
|
||||
//跨服
|
||||
if(RankContext.isCrossRank2(type) && RankContext.isCrossRank(type)){
|
||||
// 获取分组id,是否跨服
|
||||
int crossGroup = GlobleSystemLogic.getInstence().getCrossGroup();
|
||||
if(crossGroup != -1){
|
||||
AbstractRank rank = RankContext.getRankEnum(type);
|
||||
// 获取跨服key
|
||||
String key = RedisUtil.getInstence().getKeyNew(rank.getCrossRedisKey(),"");
|
||||
// 清理旧榜数据
|
||||
RedisUtil.getInstence().del(key);
|
||||
// 获取本组的服务器列表
|
||||
List<String> servers = GlobleSystemLogic.getInstence().getCrossServersByGroup();
|
||||
for (String server : servers) {
|
||||
String localKey = RedisUtil.getInstence().getKeyNew(server, rank.getRedisKey());
|
||||
// 获取本地服排行榜数据
|
||||
Set<ZSetOperations.TypedTuple<String>> range =
|
||||
RedisUtil.getInstence().getZsetreverseRangeWithScores(localKey,"",0,100, false);
|
||||
if (range == null || range.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
// 批量放入跨服排行榜
|
||||
RedisUtil.getInstence().zsetAddAall(key,range);
|
||||
// if (!isTime()) {
|
||||
// return;
|
||||
// }
|
||||
long now = TimeUtils.now();
|
||||
LOGGER.info("跨服排行榜处理开始=========当前时间:{},当前线程名称:{}",TimeUtils.getTimeStamp2(now), Thread.currentThread().getName());
|
||||
// 全部排行遍历
|
||||
for (RankEnum value : RankEnum.values()) {
|
||||
int type = value.getType();
|
||||
//跨服
|
||||
if(RankContext.isCrossRank2(type) && RankContext.isCrossRank(type)){
|
||||
// 获取分组id,是否跨服
|
||||
int crossGroup = GlobleSystemLogic.getInstence().getCrossGroup();
|
||||
if(crossGroup != -1){
|
||||
AbstractRank rank = RankContext.getRankEnum(type);
|
||||
// 获取跨服key
|
||||
String key = RedisUtil.getInstence().getKeyNew(rank.getCrossRedisKey(),"");
|
||||
// 清理旧榜数据
|
||||
RedisUtil.getInstence().del(key);
|
||||
// 获取本组的服务器列表
|
||||
List<String> servers = GlobleSystemLogic.getInstence().getCrossServersByGroup();
|
||||
for (String server : servers) {
|
||||
String localKey = RedisUtil.getInstence().getKeyNew(server, rank.getRedisKey());
|
||||
// 获取本地服排行榜数据
|
||||
Set<ZSetOperations.TypedTuple<String>> range =
|
||||
RedisUtil.getInstence().getZsetreverseRangeWithScores(localKey,"",0,100, false);
|
||||
if (range == null || range.isEmpty()){
|
||||
continue;
|
||||
}
|
||||
LOGGER.info("=====================跨服排行榜处理========,key:{}",key);
|
||||
// 批量放入跨服排行榜
|
||||
RedisUtil.getInstence().zsetAddAall(key,range);
|
||||
}
|
||||
LOGGER.info("跨服排行榜处理========= redis键: {}",key);
|
||||
}
|
||||
}
|
||||
}
|
||||
LOGGER.info("跨服排行榜处理完成=========耗时:{}ms", TimeUtils.now() - now);
|
||||
}
|
||||
|
||||
/**
|
||||
* 每隔两小时刷新一次
|
||||
* @return
|
||||
*/
|
||||
private boolean isTime(){
|
||||
int group = GlobleSystemLogic.getInstence().getCrossGroup();
|
||||
|
|
@ -89,7 +92,7 @@ public class CrossRankManager {
|
|||
return false;
|
||||
}
|
||||
String timeStamp2 = TimeUtils.getTimeStamp2(TimeUtils.now() + TimeUtils.HOUR * 2);
|
||||
RedisUtil.getInstence().set(key,timeStamp2,TimeUtils.HOUR*2/1000);
|
||||
RedisUtil.getInstence().set(key,timeStamp2,TimeUtils.HOUR * 2 / 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.ljsd.jieling.thread;
|
|||
|
||||
import com.ljsd.IManager;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.rank.CrossRankManager;
|
||||
import com.ljsd.jieling.thread.task.*;
|
||||
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
|
||||
import com.ljsd.jieling.util.TaskKit;
|
||||
|
|
@ -123,6 +124,8 @@ public class ThreadManager implements IManager {
|
|||
TaskKit.scheduleAtFixedRate(new ForceRankTask(), 60,5, TimeUnit.SECONDS);
|
||||
// 每小时减容用户缓存
|
||||
TaskKit.scheduleAtFixedRate(UserManager::checkOffline, 2, 1, TimeUnit.HOURS);
|
||||
// 跨服排行榜 每俩小时运行一次
|
||||
TaskKit.scheduleAtFixedRate(CrossRankManager::crossRankHandle, 60, 7200, TimeUnit.SECONDS);
|
||||
// 定时重启线程池
|
||||
scheduledFutureSets.add(scheduledExecutor.scheduleAtFixedRate(new Thread(() -> {
|
||||
long lastMilis = System.currentTimeMillis();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import com.ljsd.jieling.logic.family.DeathPathLogic;
|
|||
import com.ljsd.jieling.logic.family.GuildFightLogic;
|
||||
import com.ljsd.jieling.logic.mail.MailLogic;
|
||||
import com.ljsd.jieling.logic.question.QuestionLogic;
|
||||
import com.ljsd.jieling.logic.rank.CrossRankManager;
|
||||
import com.ljsd.jieling.logic.rank.RankLogic;
|
||||
import com.ljsd.jieling.logic.store.BuyGoodsNewLogic;
|
||||
import com.ljsd.jieling.logic.store.StoreLogic;
|
||||
|
|
@ -80,15 +79,6 @@ public class MinuteTask extends Thread {
|
|||
e.printStackTrace();
|
||||
LOGGER.error("Exception::=>{}", e.toString());
|
||||
}
|
||||
// try {
|
||||
// if (TimeUtils.getHourOfDay() == 21 && TimeUtils.getMinute() == 0) {
|
||||
// // 竞技场,每日晚九点刷新
|
||||
// ArenaLogic.getInstance().sendReward(GlobalsDef.ARENA_DAILY_REWARD);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// LOGGER.error("竞技场Exception::=>{}", e.toString());
|
||||
// }
|
||||
|
||||
try {
|
||||
// 每天晚上10点半,英雄热度排行榜同步更新英雄表
|
||||
|
|
@ -107,6 +97,7 @@ public class MinuteTask extends Thread {
|
|||
e.printStackTrace();
|
||||
LOGGER.error("Exception::=>{}", e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
everyHourTask();
|
||||
} catch (Exception e) {
|
||||
|
|
@ -176,13 +167,6 @@ public class MinuteTask extends Thread {
|
|||
// LOGGER.error("Exception::=>{}", e.toString());
|
||||
// }
|
||||
|
||||
try {
|
||||
CrossRankManager.getInstance().crossRankHandle();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("跨服排行榜初始化异常,Exception::=>{}", e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
ArenaLogic.getInstance().checkState();
|
||||
} catch (Exception e) {
|
||||
|
|
@ -236,7 +220,7 @@ public class MinuteTask extends Thread {
|
|||
//保证每分钟线程
|
||||
try {
|
||||
// 计算世界等级
|
||||
GlobleSystemLogic.getInstence().calCulRank(false);
|
||||
// GlobleSystemLogic.getInstence().calCulRank(false);
|
||||
//玉虚论道重置
|
||||
if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
|
||||
CrossYuxulundaoLogic.getInstance().initRank();
|
||||
|
|
|
|||
Loading…
Reference in New Issue