diff --git a/src/main/java/com/snowcattle/game/excutor/event/impl/DispatchUpdateEventListener.java b/src/main/java/com/snowcattle/game/excutor/event/impl/DispatchUpdateEventListener.java index 62bbced..547b119 100644 --- a/src/main/java/com/snowcattle/game/excutor/event/impl/DispatchUpdateEventListener.java +++ b/src/main/java/com/snowcattle/game/excutor/event/impl/DispatchUpdateEventListener.java @@ -12,6 +12,7 @@ import com.snowcattle.game.excutor.thread.listener.LockSupportUpdateFutureListener; import com.snowcattle.game.excutor.update.IUpdate; import com.snowcattle.game.excutor.utils.Constants; +import com.snowcattle.game.excutor.utils.Loggers; /** * Created by jiangwenping on 17/1/11. @@ -26,6 +27,9 @@ public DispatchUpdateEventListener(LockSupportDisptachThread dispatchThread, Upd public void fireEvent(IEvent event) { +// if(Loggers.utilLogger.isDebugEnabled()){ +// Loggers.utilLogger.debug("处理update"); +// } super.fireEvent(event); //提交执行线程 diff --git a/src/main/java/com/snowcattle/game/excutor/thread/SingleLockSupportUpdateThread.java b/src/main/java/com/snowcattle/game/excutor/thread/SingleLockSupportUpdateThread.java index 0b0a688..972f2ba 100644 --- a/src/main/java/com/snowcattle/game/excutor/thread/SingleLockSupportUpdateThread.java +++ b/src/main/java/com/snowcattle/game/excutor/thread/SingleLockSupportUpdateThread.java @@ -7,6 +7,7 @@ import com.snowcattle.game.excutor.utils.Constants; import com.snowcattle.game.excutor.utils.Loggers; +import javax.swing.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -15,6 +16,7 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.locks.LockSupport; +import java.util.logging.Logger; /** * Created by jwp on 2017/2/23. @@ -57,6 +59,8 @@ public void run() { excutorUpdate.update(); updateSize++; finishList.add(excutorUpdate); + }else{ + break; } } catch (Exception e) { Loggers.errorLogger.error(e.toString(), e); @@ -70,6 +74,13 @@ public void run() { } cleanFetch(); + + //这里会运行的太快,需要阻塞 + try { + fetchUpdates.take(); + } catch (InterruptedException e) { + Loggers.errorLogger.error(e.toString(), e); + } } } @@ -102,9 +113,12 @@ public void sendFinish(IUpdate excutorUpdate) { } public void sendFinishList(){ + //事件总线增加更新完成通知 for(IUpdate excutorUpdate : finishList){ -// System.out.println(excutorUpdate.getId() + "存活" + excutorUpdate.isActive()); +// if(Loggers.utilLogger.isDebugEnabled()) { +// Loggers.utilLogger.debug(excutorUpdate.getId() + "发送存活" + excutorUpdate.isActive()); +// } sendFinish(excutorUpdate); } finishList.clear(); diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index ddaa9a4..287ebfc 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -1,6 +1,6 @@ log4j.rootLogger=info,stdout,error -log4j.logger.gameExcutorUtil=info,gameExcutorUtil -log4j.logger.gameExcutorError=info,gameExcutorError +log4j.logger.gameExcutorUtil=debug,gameExcutorUtil +log4j.logger.gameExcutorError=debug,gameExcutorError #--------------------stdout-------------------------------- log4j.appender.stdout=org.apache.log4j.ConsoleAppender diff --git a/src/test/java/com/snowcattle/game/excutor/event/async/IntegerUpdate.java b/src/test/java/com/snowcattle/game/excutor/event/async/IntegerUpdate.java index 8a9c8a7..d017aaf 100644 --- a/src/test/java/com/snowcattle/game/excutor/event/async/IntegerUpdate.java +++ b/src/test/java/com/snowcattle/game/excutor/event/async/IntegerUpdate.java @@ -17,7 +17,7 @@ public IntegerUpdate(long id) { @Override public void update() { incrId++; - if (incrId == 2) { + if (incrId == 2000) { setActive(false); } if (Loggers.utilLogger.isDebugEnabled()) { diff --git a/src/test/java/com/snowcattle/game/excutor/event/asyncevent/AsyncEventTest.java b/src/test/java/com/snowcattle/game/excutor/event/asyncevent/AsyncEventTest.java index a0bfba7..67f73fd 100644 --- a/src/test/java/com/snowcattle/game/excutor/event/asyncevent/AsyncEventTest.java +++ b/src/test/java/com/snowcattle/game/excutor/event/asyncevent/AsyncEventTest.java @@ -28,14 +28,14 @@ public static void testEvent() throws Exception { EventBus updateEventBus = new EventBus(); // int maxSize = 10000; // int corePoolSize = 100; - int maxSize = 1; - int corePoolSize = 1; + int maxSize = 2; + int corePoolSize = 2; long keepAliveTime = 60; TimeUnit timeUnit = TimeUnit.SECONDS; UpdateEventExcutorService updateEventExcutorService = new UpdateEventExcutorService(corePoolSize); int cycleSleepTime = 1000 / Constants.cycle.cycleSize; LockSupportEventDisptachThread dispatchThread = new LockSupportEventDisptachThread(updateEventBus, updateEventExcutorService - , cycleSleepTime, cycleSleepTime*1000000); + , cycleSleepTime, cycleSleepTime*1000); updateEventExcutorService.setDispatchThread(dispatchThread); UpdateService updateService = new UpdateService(dispatchThread, updateEventExcutorService); updateEventBus.addEventListener(new DispatchCreateEventListener(dispatchThread, updateService)); diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties index b0652a6..287ebfc 100644 --- a/src/test/resources/log4j.properties +++ b/src/test/resources/log4j.properties @@ -1,5 +1,6 @@ log4j.rootLogger=info,stdout,error log4j.logger.gameExcutorUtil=debug,gameExcutorUtil +log4j.logger.gameExcutorError=debug,gameExcutorError #--------------------stdout-------------------------------- log4j.appender.stdout=org.apache.log4j.ConsoleAppender @@ -22,9 +23,18 @@ log4j.appender.gameExcutorUtil=org.apache.log4j.DailyRollingFileAppender log4j.appender.gameExcutorUtil.encoding=UTF-8 log4j.appender.gameExcutorUtil.append=true log4j.appender.gameExcutorUtil.datePattern='.'yyyy-MM-dd -log4j.appender.gameExcutorUtil.File=logs/gameExcutorUtil.log +log4j.appender.gameExcutorUtil.File=logs/util.log log4j.appender.gameExcutorUtil.layout=org.apache.log4j.PatternLayout log4j.appender.gameExcutorUtil.layout.ConversionPattern=%d{HH:mm:ss} - %m%n +#--------------------gameExcutorError-------------------------------- +log4j.appender.gameExcutorError=org.apache.log4j.DailyRollingFileAppender +log4j.appender.gameExcutorError.encoding=UTF-8 +log4j.appender.gameExcutorError.append=true +log4j.appender.gameExcutorError.datePattern='.'yyyy-MM-dd +log4j.appender.gameExcutorError.File=logs/gameExcutorError.log +log4j.appender.gameExcutorError.layout=org.apache.log4j.PatternLayout +log4j.appender.gameExcutorError.layout.ConversionPattern=%d{HH:mm:ss} - %m%n +