从UncaughtExceptionHandler在线程“主”中抛出的java.lang.OutOfMemoryError大于4GB

时间:2019-03-20 13:17:16

标签: java heap

使用此工具https://github.com/citygml4j/citygml-tools,称为to-cityjson。我想将cityGML文件转换为cityJSON文件。该文件为4.36 GB,但出现以下错误:

从线程java.lang.OutOfMemoryError

UncaughtExceptionHandler抛出的

main

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at jdk.internal.reflect.GeneratedConstructorAccessor183.newInstance(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at com.sun.xml.bind.v2.ClassFactory.create0(ClassFactory.java:102)
    at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.createInstance(ClassBeanInfoImpl.java:255)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(UnmarshallingContext.java:672)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:158)
    at com.sun.xml.bind.v2.runtime.unmarshaller.ProxyLoader.startElement(ProxyLoader.java:30)
    at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$IntercepterLoader.startElement(ElementBeanInfoImpl.java:223)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:547)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:526)
    at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:45)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:216)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:150)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:385)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:356)
    at org.citygml4j.builder.jaxb.xml.io.reader.JAXBSimpleReader.nextFeature(JAXBSimpleReader.java:133)
    at org.citygml4j.tools.command.ToCityJSONCommand.execute(ToCityJSONCommand.java:133)
    at org.citygml4j.tools.CityGMLTools.handleParseResult(CityGMLTools.java:102)
    at org.citygml4j.tools.CityGMLTools.handleParseResult(CityGMLTools.java:35)
    at picocli.CommandLine.parseWithHandlers(CommandLine.java:1526)
    at org.citygml4j.tools.CityGMLTools.main(CityGMLTools.java:44)

我找到了一种解决方案,那就是使用java -Xmx15G,但我不知道如何实现。

3 个答案:

答案 0 :(得分:2)

您可以使用JAVA_OPTS可执行文件读取的CITYGML_TOOLS_OPTScitygml-tools环境变量。或者,您可以在DEFAULT_JVM_OPTS代码中修改citygml-tools选项:

# Add default JVM options here. You can also use JAVA_OPTS and CITYGML_TOOLS_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xms1G"'

如果您使用的是Linux,则可以在终端中进行设置:

export JAVA_OPTS="-Xmx15G"
citygml-tools <file>

答案 1 :(得分:0)

java -Xmx6144M -d64

转到命令行并执行此命令,它将设置为64 GB

来源:Increase heap size in Java

答案 2 :(得分:0)

您可以尝试使用蛮力方法并分配非常大的健康空间

该行的Grep

 defaultJvmOpts = ['-Xms1G'] 

仅1 GiB的堆空间

还要确保您使用的是64位Java并具有足够的内存