Hystrix is optimized for adaptation

pull/284/head
shining-stars-lk 3 years ago
parent 23daaa426f
commit 83969bcd78

@ -74,7 +74,6 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner {
ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler(); ScheduledExecutorService scheduler = threadPoolAdapterScheduler.getScheduler();
int taskIntervalSeconds = threadPoolAdapterScheduler.getTaskIntervalSeconds(); int taskIntervalSeconds = threadPoolAdapterScheduler.getTaskIntervalSeconds();
ThreadPoolAdapterRegisterTask threadPoolAdapterRegisterTask = new ThreadPoolAdapterRegisterTask(scheduler, taskIntervalSeconds); ThreadPoolAdapterRegisterTask threadPoolAdapterRegisterTask = new ThreadPoolAdapterRegisterTask(scheduler, taskIntervalSeconds);
scheduler.schedule(threadPoolAdapterRegisterTask, threadPoolAdapterScheduler.getTaskIntervalSeconds(), TimeUnit.SECONDS); scheduler.schedule(threadPoolAdapterRegisterTask, threadPoolAdapterScheduler.getTaskIntervalSeconds(), TimeUnit.SECONDS);
} }
@ -131,16 +130,35 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner {
@Override @Override
public void run() { public void run() {
try { try {
boolean registerFlag = false;
List<ThreadPoolAdapterCacheConfig> newThreadPoolAdapterCacheConfigs = getThreadPoolAdapterCacheConfigs(); List<ThreadPoolAdapterCacheConfig> newThreadPoolAdapterCacheConfigs = getThreadPoolAdapterCacheConfigs();
boolean registerFlag = compareThreadPoolAdapterCacheConfigs(newThreadPoolAdapterCacheConfigs, cacheConfigList);
cacheConfigList = newThreadPoolAdapterCacheConfigs;
if (registerFlag) {
doRegister(cacheConfigList);
}
}catch (Exception e){
log.error("Register Task Error",e);
}finally {
if (!scheduler.isShutdown()) {
scheduler.schedule(this, taskIntervalSeconds, TimeUnit.MILLISECONDS);
}
}
}
}
private boolean compareThreadPoolAdapterCacheConfigs(List<ThreadPoolAdapterCacheConfig> newThreadPoolAdapterCacheConfigs,
List<ThreadPoolAdapterCacheConfig> oldThreadPoolAdapterCacheConfigs){
boolean registerFlag = false;
Map<String, List<ThreadPoolAdapterState>> newThreadPoolAdapterCacheConfigMap = Map<String, List<ThreadPoolAdapterState>> newThreadPoolAdapterCacheConfigMap =
newThreadPoolAdapterCacheConfigs.stream().collect(Collectors.toMap( newThreadPoolAdapterCacheConfigs.stream().collect(Collectors.toMap(
ThreadPoolAdapterCacheConfig::getMark, ThreadPoolAdapterCacheConfig::getThreadPoolAdapterStates, (k1, k2) -> k2)); ThreadPoolAdapterCacheConfig::getMark, ThreadPoolAdapterCacheConfig::getThreadPoolAdapterStates, (k1, k2) -> k2));
Map<String, List<ThreadPoolAdapterState>> oldThreadPoolAdapterCacheConfigMap = Map<String, List<ThreadPoolAdapterState>> oldThreadPoolAdapterCacheConfigMap =
cacheConfigList.stream().collect(Collectors.toMap( oldThreadPoolAdapterCacheConfigs.stream().collect(Collectors.toMap(
ThreadPoolAdapterCacheConfig::getMark, ThreadPoolAdapterCacheConfig::getThreadPoolAdapterStates, (k1, k2) -> k2)); ThreadPoolAdapterCacheConfig::getMark, ThreadPoolAdapterCacheConfig::getThreadPoolAdapterStates, (k1, k2) -> k2));
for (Map.Entry<String, List<ThreadPoolAdapterState>> entry : newThreadPoolAdapterCacheConfigMap.entrySet()) { for (Map.Entry<String, List<ThreadPoolAdapterState>> entry : newThreadPoolAdapterCacheConfigMap.entrySet()) {
@ -157,19 +175,6 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner {
} }
} }
} }
return registerFlag;
cacheConfigList = newThreadPoolAdapterCacheConfigs;
if (registerFlag) {
doRegister(cacheConfigList);
}
}catch (Exception e){
log.error("Register Task Error",e);
}finally {
if (!scheduler.isShutdown()) {
scheduler.schedule(this, taskIntervalSeconds, TimeUnit.MILLISECONDS);
}
}
}
} }
} }

Loading…
Cancel
Save