Merge branch 'master_dev' into master_otnew

master_otnew
grimm 2023-12-26 12:46:03 +08:00
commit 8f421d9147
5 changed files with 17 additions and 18 deletions

View File

@ -86,7 +86,7 @@ public class ChatLogic {
chatInfoList.add(CBean2Proto.getChatInfoBuilder(user, message,time,0));
}
}
if (hmget!= null && hmget.size() != 0){
if (hmget!= null && !hmget.isEmpty()){
//取出数据好友聊天数据后删除
RedisUtil.getInstence().del(GameApplication.serverId + RedisKey.CUser_Chat + uid);
}

View File

@ -295,19 +295,16 @@ public class SessionManager implements INetSession<ISession>, INetReceived<ISess
}
private int checkIndex(ISession iSession, PacketNetData packetNetData) {
/* if(packetNetData.getMsgId() == MessageTypeProto.MessageType.LOGIN_REQUEST_VALUE || packetNetData.getMsgId() == MessageTypeProto.MessageType.RECONNECT_REQUEST_VALUE){
return 0;
}*/
int index = packetNetData.getIndex();
if (iSession.getIndex() >= index) {
byte[] message = iSession.getCacheMessage(index);
if (message == null) {
//TODO error
LOGGER.info("the uid={},the msg={} is processing,the index={},the sessionIndex={}", iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()), index, iSession.getIndex());
LOGGER.error("the uid={},the msg={} is processing,the index={},the sessionIndex={}", iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()), index, iSession.getIndex());
return 1;
} else {
LOGGER.info("the uid={},the msg={} reback", iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()));
LOGGER.error("the uid={},the msg={} reback", iSession.getUid(), MessageTypeProto.MessageType.valueOf(packetNetData.getMsgId()));
iSession.writeAndFlush(message);
return 1;
}

View File

@ -2,6 +2,7 @@ package com.ljsd.jieling.thread;
import com.ljsd.IManager;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.thread.task.*;
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
import org.slf4j.Logger;
@ -118,6 +119,8 @@ public class ThreadManager implements IManager {
scheduledFutureSets.add(scheduledExecutor.scheduleAtFixedRate(new SecondsTask(), delayForMinute + 10, 1, TimeUnit.SECONDS));
// 战力任务
scheduledFutureSets.add(scheduledExecutor.scheduleAtFixedRate(new ForceRankTask(), 60,5, TimeUnit.SECONDS));
// 每小时减容用户缓存
scheduledFutureSets.add(scheduledExecutor.scheduleAtFixedRate(UserManager::adjustCacheBasedOnCurrentLoad, 10, 60, TimeUnit.MINUTES));
// 定时重启线程池
scheduledFutureSets.add(scheduledExecutor.scheduleAtFixedRate(new Thread(() -> {
long lastMilis = System.currentTimeMillis();

View File

@ -170,12 +170,12 @@ public class MinuteTask extends Thread {
LOGGER.error("Exception::=>{}", e.toString());
}
try {
OnlineUserManager.checkOnline();
} catch (Exception e) {
e.printStackTrace();
LOGGER.error("Exception::=>{}", e.toString());
}
// try {
// OnlineUserManager.checkOnline();
// } catch (Exception e) {
// e.printStackTrace();
// LOGGER.error("Exception::=>{}", e.toString());
// }
try {
CrossRankManager.getInstance().crossRankHandle();

View File

@ -3,10 +3,7 @@ package com.ljsd.jieling.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@ -99,16 +96,18 @@ public class DynamicLRUCache<K, V> {
public void shrinkToFit() {
lock.writeLock().lock();
try {
if (cache.size() < maxSize / 2) {
// 减少缓存大小调整的频率
if (cache.size() < maxSize / 2 && maxSize > 100) {
maxSize /= 2; // 缩小缓存容量
}
cache.entrySet().removeIf(entry -> isEntryExpired(entry.getValue()));
} finally {
lock.writeLock().unlock();
}
LOGGER.info("当前用户缓存列表大小num{}max{}",size(),maxSize);
LOGGER.info("当前用户缓存列表大小num{}max{}", size(), maxSize);
}
private boolean isEntryExpired(TimedCacheEntry<V> entry) {
return System.currentTimeMillis() - entry.timestamp > expireTime;
}