2012-10-11 68 views
1

我正在嘗試讀取大小爲10 MB的xml文件。我使用Windows7操作系統(8GB RAM),Netbeans 7.1.2如何解決線程「AWT-EventQueue-0」中的異常java.lang.OutOfMemoryError:Java堆空間

C:\>java -version 
    java version "1.7.0_05" 
    Java(TM) SE Runtime Environment (build 1.7.0_05-b05) 
    Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode) 

C:\>free -m 
      total  used  free  shared buffers  cached 
Mem:   8169  3175  4993   0   0   0 
-/+ buffers/cache:  3175  4993 
Swap:   8169   81  8087 

我試過C:\>java -Xms5120m -Xmx6144m但是沒有幫助。

堆棧跟蹤:

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space 
    at org.apache.xerces.xni.XMLString.toString(Unknown Source) 
    at org.apache.xerces.parsers.AbstractDOMParser.characters(Unknown Source) 
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanContent(Unknown Source) 
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) 
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) 
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) 
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) 
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208) 
    at ReadExcel.xmlappend(ReadExcel.java:343) 
    at ReadExcel.jButton7ActionPerformed(ReadExcel.java:331) 
    at ReadExcel.access$600(ReadExcel.java:42) 
    at ReadExcel$7.actionPerformed(ReadExcel.java:176) 
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) 
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) 
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) 
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) 
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) 
    at java.awt.Component.processMouseEvent(Component.java:6038) 
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3260) 
    at java.awt.Component.processEvent(Component.java:5803) 
    at java.awt.Container.processEvent(Container.java:2058) 
    at java.awt.Component.dispatchEventImpl(Component.java:4410) 
    at java.awt.Container.dispatchEventImpl(Container.java:2116) 
    at java.awt.Component.dispatchEvent(Component.java:4240) 
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) 
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986) 
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916) 
    at java.awt.Container.dispatchEventImpl(Container.java:2102) 
    at java.awt.Window.dispatchEventImpl(Window.java:2429) 
+0

你能發佈異常和導致它的代碼的堆棧跟蹤嗎? –

回答

1

我懷疑你的10 MB的數據產生大量圖形對象或其他重物的對象。最簡單的檢查方法是添加-XX+HeapDumpOnOutOfMemoryError並分析所有內存的使用位置。

您可能希望減小最大堆大小,因爲某些工具(例如VisualVM)在加載大型堆轉儲時遇到困難,所以轉儲量較小。

Browsing a Heap Dump with VisualVM

+0

你能簡單介紹一下怎麼做。 –

+0

將該選項添加到命令行並以較小的最大值再次運行該程序,例如, '-mx1g'。這將觸發一個堆轉儲,您可以通過運行'jvisualvm'打開它 –

相關問題