這個問題發生在我身上只有在生產和是我自己無法測試/開發Java靜態數組列表初始化問題
期間重現它,我有一個包含大量靜態變量的類。
public class MyClass {
private static final ArrayList<String> MY_LIST = new ArrayList<String>(Arrays.asList("DCNC", "DJPC", "DKRC", "DTHC", "DTWC", "DILC", "DALC", "DSEC", "DTRC", "DZAC", "DARC", "DCOC", "DRUC", "DMYC", "DMXC", "DPKC", "DIDC", "DBRC", "DNPC", "DJOC", "DLKC", "DVNC", "DKHC", "DLAC"));
public static final HashMap<String, ArrayList<String>> MY_MAP = new HashMap<String, ArrayList<String>>();
static {
MY_MAP.put("test1", MY_LIST);
MY_MAP.put("test2", MY_LIST);
MY_MAP.put("test3", MY_LIST);
MY_MAP.put("test4", MY_LIST);
MY_MAP.put("test5", MY_LIST);
MY_MAP.put("test6", MY_LIST);
}
private static final ArrayList<String> MY_SECOND_LIST = new ArrayList<String>(Arrays.asList("DCNC", "DJPC", "DKRC", "DTHC", "DTWC", "DILC", "DALC", "DSEC", "DTRC", "DZAC", "DARC", "DCOC", "DRUC", "DMYC", "DMXC", "DPKC", "DIDC", "DBRC", "DNPC", "DJOC", "DLKC", "DVNC", "DKHC", "DLAC"));
private static final ArrayList<String> MY_THIRD_LIST = new ArrayList<String>(Arrays.asList("DJPC", "DKRC", "DTHC", "DTWC", "DILC", "DALC", "DSEC", "DTRC", "DZAC", "DARC", "DCOC", "DRUC", "DMYC", "DMXC", "DPKC", "DIDC", "DBRC", "DNPC", "DJOC", "DLKC", "DVNC", "DKHC", "DLAC"));
private static final ArrayList<String> MY_FOURTH_LIST = new ArrayList<String>(Arrays.asList("DCNC", "DKRC", "DTHC", "DTWC", "DILC", "DALC", "DSEC", "DTRC", "DZAC", "DARC", "DCOC", "DRUC", "DMYC", "DMXC", "DPKC", "DIDC", "DBRC", "DNPC", "DJOC", "DLKC", "DVNC", "DKHC", "DLAC"));
private static final ArrayList<String> MY_FIFTH_LIST = new ArrayList<String>(Arrays.asList("DKRC", "DTHC", "DTWC", "DILC", "DALC", "DSEC", "DTRC", "DZAC", "DARC", "DCOC", "DRUC", "DMYC", "DMXC", "DPKC", "DIDC", "DBRC", "DNPC", "DJOC", "DLKC", "DVNC", "DKHC", "DLAC"));
public static final HashMap<String, ArrayList<String>> MY_SECOND_MAP = new HashMap<String, ArrayList<String>>();
static {
MY_SECOND_MAP.put("T1", MY_SECOND_LIST);
MY_SECOND_MAP.put("T2", MY_THIRD_LIST);
MY_SECOND_MAP.put("T3", MY_FOURTH_LIST);
MY_SECOND_MAP.put("T4", MY_FIFTH_LIST);
}
}
當我訪問MY_MAP.get("test1")
或MY_MAP.get("test2")
或上MY_MAP
任意鍵這個問題,我總是空單。看起來由於某種原因,MY_LIST
被初始化爲空列表。
任何人都可以告訴在什麼情況下會發生這種情況?這種情況在生產環境中經常發生,但無法在本地重現。
環境細節:
- 紅帽企業5.3服務器64位(更新U3)
- JDK7
- JVM選項
--FLApplication.machineProtocol = UDP -Dclient .encoding.override = UTF-8 -Dfile.encoding = UTF-8 -Xmx512m -Xms512m -XX:SurvivorRatio = 8 -XX:PermSize = 128M -XX:MaxPermSize = 128M -XX:+ CMSClassUnloadingEnabled -XX:+ CMS PermGenSweepingEnabled代表@Marko Topolnik的
生產,認真嗎? –
是............. –
請指定環境:操作系統,Java版本,jvm選項。你使用多線程嗎? – sibnick