public void run() { int cmdID = 0; long processTime = 0L; long processWaitTime = 0L; if (Monitor.TryEnter(this.session.Lock)) { try { long processBeginTime = TimeUtil.NowEx(); processWaitTime = processBeginTime - this.beginTime; TCPCmdWrapper wrapper = this.session.getNextTCPCmdWrapper(); if (null != wrapper) { try { TCPCmdHandler.ProcessCmd(wrapper.TcpMgr, wrapper.TMSKSocket, wrapper.TcpClientPool, wrapper.TcpRandKey, wrapper.Pool, wrapper.NID, wrapper.Data, wrapper.Count); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, string.Format("指令处理错误:{0},{1}", Global.GetDebugHelperInfo(wrapper.TMSKSocket), (TCPGameServerCmds)wrapper.NID), false, false); } ProcessSessionTask.processCmdNum += 1L; processTime = TimeUtil.NowEx() - processBeginTime; ProcessSessionTask.processTotalTime += processWaitTime + processTime; cmdID = wrapper.NID; wrapper.release(); wrapper = null; } } catch (Exception ex) { throw ex; } finally { Monitor.Exit(this.session.Lock); } if (cmdID > 0) { TCPManager.RecordCmdDetail2(cmdID, processTime, processWaitTime); } } else { TCPManager.getInstance().taskExecutor.scheduleExecute(this, 5L); } }
public void run() { // lock (session.Lock) // { // // } int cmdID = 0; long processTime = 0L; long processWaitTime = 0L; //因为业务层处理时未做同步,暂时锁会话,保证每个玩家的指令处理时线性的 if (Monitor.TryEnter(session.Lock)) { try { long processBeginTime = TimeUtil.NowEx(); processWaitTime = processBeginTime - beginTime; TCPCmdWrapper wrapper = session.getNextTCPCmdWrapper(); if (null != wrapper) { try { TCPCmdHandler.ProcessCmd(wrapper.TcpMgr, wrapper.TMSKSocket, wrapper.TcpClientPool, wrapper.TcpRandKey, wrapper.Pool, wrapper.NID, wrapper.Data, wrapper.Count); } catch (Exception ex) { DataHelper.WriteFormatExceptionLog(ex, string.Format("指令处理错误:{0},{1}", Global.GetDebugHelperInfo(wrapper.TMSKSocket), (TCPGameServerCmds)wrapper.NID), false); } processCmdNum++; processTime = (TimeUtil.NowEx() - processBeginTime); processTotalTime += (processWaitTime + processTime); cmdID = wrapper.NID; wrapper.release(); wrapper = null; } } catch (Exception ex) { throw ex; } finally { Monitor.Exit(session.Lock); } if (cmdID > 0) { TCPManager.RecordCmdDetail2(cmdID, processTime, processWaitTime); } } else { //如果当session有指令正在处理,把当前指令重新丢进队列,延迟5毫秒处理,防止同一session占用过多线程,保证资源合理利用 TCPManager.getInstance().taskExecutor.scheduleExecute(this, 5); } }