Skip to content

Commit

Permalink
增加外部通知notify
Browse files Browse the repository at this point in the history
  • Loading branch information
jwpttcg66 committed Mar 28, 2017
1 parent b6f6e1e commit d7fd7a0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ private void singleCycle(boolean sleepFlag){
long time = System.nanoTime();
int cycleSize = getEventBus().getEventsSize();
int size = getEventBus().cycle(cycleSize);
park();

if(sleepFlag) {
park();
long notifyTime = System.nanoTime();
long diff = (int) (notifyTime - time);
if (diff < minCycleTime && diff > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
* Created by jwp on 2017/3/28.
Expand All @@ -28,7 +29,7 @@ public static void testEvent() throws Exception {
EventBus updateEventBus = new EventBus();
// int maxSize = 10000;
// int corePoolSize = 100;
int maxSize = 20;
int maxSize = 2;
int corePoolSize = 2;
long keepAliveTime = 60;
TimeUnit timeUnit = TimeUnit.SECONDS;
Expand All @@ -43,27 +44,31 @@ public static void testEvent() throws Exception {
updateEventBus.addEventListener(new DispatchFinishEventListener(dispatchThread, updateService));

updateService.notifyStart();
// while (true) {
// Thread.currentThread().sleep(100);
// LockSupport.unpark(dispatchThread);
//
// LockSupport.park(dispatchThread);
// updateService.notifyRun();
// break;
// }


for (long i = 0; i < maxSize; i++) {
IntegerUpdate integerUpdate = new IntegerUpdate(i);
EventParam<IntegerUpdate> param = new EventParam<IntegerUpdate>(integerUpdate);
CycleEvent cycleEvent = new CycleEvent(Constants.EventTypeConstans.readyCreateEventType, integerUpdate.getId(), param);
updateService.addReadyCreateEvent(cycleEvent);
}

while (true){
Thread.currentThread().sleep(1000);
dispatchThread.unpark();
updateService.notifyRun();
}
// updateService.shutDown();
// Timer timer = new Timer();
//
// timer.schedule(new NotifyTask(updateService), 0, 1);
// while (true) {
// Thread.currentThread().sleep(100);
// updateService.toString();
// }

// updateService.shutDown();
Timer timer = new Timer();
timer.schedule(new NotifyTask(updateService), 0, 10);
while (true) {
Thread.currentThread().sleep(100);
updateService.toString();
}
}
}

0 comments on commit d7fd7a0

Please sign in to comment.