فهرست منبع

Fix PAIModel init order: lazy init to avoid NPE

PAIModel constructor calls FGEncoderManager.getFGEncoder() which
requires registerAllFGEncoder() to have been called first in
WarmUpService. Change from eager singleton to double-checked
locking lazy init so PAIModel is created on first use, after
WarmUpService has completed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
yangxiaohui 1 ماه پیش
والد
کامیت
3a18b4a8e7

+ 8 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/model/PAIModel.java

@@ -28,7 +28,7 @@ public class PAIModel {
     private PredictClient predictClient;
     private List<Tuple4<String, String, String, TFDataType>> featureKeys = new ArrayList<>();
 
-    private static final PAIModel MODEL = new PAIModel();
+    private static volatile PAIModel MODEL;
 
     private PAIModel() {
         this.fgConfigFilePath = "zhaohaipeng/pai/config/fg/feature_list_20260403.json";
@@ -40,8 +40,14 @@ public class PAIModel {
         this.initPredictClient();
     }
 
-
     public static PAIModel getModelInstance() {
+        if (MODEL == null) {
+            synchronized (PAIModel.class) {
+                if (MODEL == null) {
+                    MODEL = new PAIModel();
+                }
+            }
+        }
         return MODEL;
     }