[英]Getting out of memory issue while Marshaling large number of objects in XML using JAXB
[英]Getting Out of memory error while comparing two large xml files
我正在嘗試比較XMLUNIT的兩個大XML文件,但是卻收到“線程“主”中的異常” java.lang.OutOfMemoryError:Java堆空間”
public static void main(String[] args) throws Exception {
FileReader file = new FileReader("C:/abc/a.xml");
FileReader file1 = new FileReader("C:/abc/b.xml");
assertXMLEquals(file, file1);
}
public static void assertXMLEquals(FileReader expectedXML, FileReader actualXML) throws Exception {
DetailedDiff difference = null;
try {
// Checks each Node
difference = new DetailedDiff(XMLUnit.compareXML(expectedXML, actualXML));
} catch (Exception e) {
}
if (!difference.similar()) {
List<Difference> AllDifferences = difference.getAllDifferences();
System.out.println("Xml comparison failed because of follwoing error/s : \n"+AllDifferences);
}
}
解決方案-我在Eclipse Run配置中添加了“ -Xms2048M -Xmx2048M”作為參數。
您是否嘗試過使用SAX Parser? 它將解決您的問題,因為它不需要將整個文件加載到內存中進行處理。
順便說一句,您的文件大小是多少?
我還沒有使用xmlunit。 但是,查看xmlunit文檔,您似乎可以將流用作輸入。
例如:BufferedInputStream in = new BufferedInputStream(new FileInputStream(pathname))
使用流不會將整個文件立即加載到內存中。
但是要獲取OutOfMemoryError異常,文件應該非常大。 您還可以在啟動時增加應用程序的最大堆大小。
例如:將最小堆大小(xms)和最大堆大小(xmx)增加到2GB。
java -Xms2048mm -Xmx2048m
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.