“AWT-EventQueue-1”java.lang.OutOfMemoryError:Java堆空间

时间:2010-08-10 06:42:58

标签: java out-of-memory

我要用stanford解析器标记句子

对于每个句子我加载EnglishPCFGrammer文件并使用stanford解析器找到标签,它适用于单句,但是当我给出多个句子时,我得到这个例外..有人帮忙


Loading parser from serialized file englishPCFG.ser.gz ... done [7.7 sec].
Exception in thread "AWT-EventQueue-1" java.lang.OutOfMemoryError: Java heap space
        at edu.stanford.nlp.parser.lexparser.ExhaustivePCFGParser.createArrays(ExhaustivePCFGParser.java:2056)
        at edu.stanford.nlp.parser.lexparser.ExhaustivePCFGParser.considerCreatingArrays(ExhaustivePCFGParser.java:2027)
        at edu.stanford.nlp.parser.lexparser.ExhaustivePCFGParser.parse(ExhaustivePCFGParser.java:315)
        at edu.stanford.nlp.parser.lexparser.LexicalizedParser.parse(LexicalizedParser.java:375)
        at edu.stanford.nlp.parser.lexparser.LexicalizedParser.apply(LexicalizedParser.java:279)
        at finalproj.logic.SentenceTagger.tagSentence(SentenceTagger.java:25)
        at finalproj.logic.SentenceToXMLWriter.addSentence(SentenceToXMLWriter.java:62)
        at finalproj.logic.SentenceSplitter.splitFile(SentenceSplitter.java:24)
        at finalproj.ui.LoadReqFile.jBtnSentenceSplitActionPerformed(LoadReqFile.java:126)
        at finalproj.ui.LoadReqFile.access$200(LoadReqFile.java:21)
        at finalproj.ui.LoadReqFile$3.actionPerformed(LoadReqFile.java:70)
        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.Component.dispatchEvent(Component.java:4240)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)

2 个答案:

答案 0 :(得分:1)

  

我为每个句子加载了EnglishPCFGrammer文件

您绝对不希望为每个句子加载文件。您只需加载一次 - 在解析过程开始时,只需为每个句子引用它 听起来像为每个句子加载File肯定会导致OutOfMemoryError

答案 1 :(得分:0)

您需要使用额外参数启动java以增加堆空间。初始空间为64MB,这显然是不够的:

java -Xms128m -Xmx256m

将以128 MByte(初始堆大小)开始,并允许最大堆256Myte。你可能需要一些实验。


注意 - stanford解析器的'about'页面包含一个简短的java命令行示例(最后一行),它们使用的堆大小为200MByte。我将此视为解析器本身需要超过64MByte内存的提示。 (附加说明:此命令行示例有语法错误,我上面的示例是正确的)。