Browse Source

ADD:Merge配置文件的缓存

sunxy 1 year ago
parent
commit
b590310685

+ 8 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/framework/merger/MergeUtils.java

@@ -21,7 +21,14 @@ import java.util.*;
 public class MergeUtils {
     public static final Logger LOGGER = LoggerFactory.getLogger(MergeUtils.class);
 
+    // mergeConfFile_topQueueName 对应的 StrategyQueue 缓存
+    private static final Map<String, StrategyQueue> topQueueMap = new HashMap<>();
+
     public static StrategyQueue createTopQueue(String mergeConfFile, String topQueueName) {
+        String key = mergeConfFile + "_" + topQueueName;
+        if (topQueueMap.containsKey(key)) {
+            return topQueueMap.get(key);
+        }
         StrategyQueueConfig strategyQueueConfig = new StrategyQueueConfig();
         Config mergeQueueConf = ConfigFactory.parseResources(mergeConfFile);
         if (strategyQueueConfig.load(mergeQueueConf)) {
@@ -44,6 +51,7 @@ public class MergeUtils {
         } catch (InvocationTargetException e) {
             LOGGER.error("construct top StrategyQueue: [{}]", e);
         }
+        topQueueMap.put(key, topQueue);
         return topQueue;
     }