在String連接期間,我得到java.lang.OutOfMemoryError。有人能幫我擺脫這個嗎?以下是我的代碼的外觀。如果blokc在循環中運行,並且它處理「str」的字符串連接,則會引發OutofemoryError。任何幫助,非常感謝。String連接期間java.lang.OutOfMemoryError
for (long j = mincollectiontime; j <= maxcollectiontime; j = j
+ timeintreval) {
query = "select count(*) table1";
ResultSet result2 = VerticaDBHandler.executequery(con2, query);
System.out.println("Query:- " + query);
String str = "";
if (result2.isBeforeFirst()) {
if (mysqlconn == null) {
mysqlconn = DatabaseHandler.openDB();
}
while (result2.next()) {
int isgap = Integer.parseInt(result2.getString(1));
if (isgap == 0) {
Date startime = EpochTimeHandler.epochToTimeStamp(j);
Date endtime = EpochTimeHandler.epochToTimeStamp(j
+ timeintreval);
str = "NO DATA BETWEEN " + startime + " --- " + endtime
+ " forInstanceId: " + instanceid
+ " --InstanceName: " + instanceName + " in "
+ perfTables[i];
DatabaseHandler.LoadDB_dataGaps(mysqlconn,
perfTables[i], instanceid, instanceName,
VirtType, BelongstoDataCenter,
startime.toString(), endtime.toString(), str);
System.out.println(str);
str = "";
} else {
System.out.println("No Gap Seen");
}
}
}
}
例外。
Exception thrown:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.LinkedHashMap.newNode(LinkedHashMap.java:256)
at java.util.HashMap.putVal(HashMap.java:630)
at java.util.HashMap.put(HashMap.java:611)
at sun.util.resources.OpenListResourceBundle.loadLookup(OpenListResourceBundle.java:146)
at sun.util.resources.OpenListResourceBundle.loadLookupTablesIfNecessary(OpenListResourceBundle.java:128)
at sun.util.resources.OpenListResourceBundle.handleKeySet(OpenListResourceBundle.java:96)
at java.util.ResourceBundle.containsKey(ResourceBundle.java:1807)
at sun.util.locale.provider.LocaleResources.getTimeZoneNames(LocaleResources.java:262)
at sun.util.locale.provider.TimeZoneNameProviderImpl.getDisplayNameArray(TimeZoneNameProviderImpl.java:122)
at sun.util.locale.provider.TimeZoneNameProviderImpl.getDisplayName(TimeZoneNameProviderImpl.java:98)
at sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter.getName(TimeZoneNameUtility.java:325)
at sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter.getObject(TimeZoneNameUtility.java:281)
at sun.util.locale.provider.TimeZoneNameUtility$TimeZoneNameGetter.getObject(TimeZoneNameUtility.java:267)
at sun.util.locale.provider.LocaleServiceProviderPool.getLocalizedObjectImpl(LocaleServiceProviderPool.java:281)
at sun.util.locale.provider.LocaleServiceProviderPool.getLocalizedObject(LocaleServiceProviderPool.java:265)
at sun.util.locale.provider.TimeZoneNameUtility.retrieveDisplayName(TimeZoneNameUtility.java:135)
at java.util.TimeZone.getDisplayName(TimeZone.java:400)
at java.util.Date.toString(Date.java:1045)
at java.lang.String.valueOf(String.java:2982)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at com.test.perf.testpgm.main(testpgm.java:112)
需要查看更多代碼。發佈for循環?另外,你已經嘗試過什麼?你有沒有試過調試器? – Aify
你能不能粘貼整個班級 – nullpointer
完整的代碼在內嵌上面編輯 – Vikram