gpt4 book ai didi

java.lang.OutOfMemory错误: Java heap space with JSON conversion

转载 作者:行者123 更新时间:2023-11-30 03:06:25 24 4
gpt4 key购买 nike

listaDecretoSingolo = new ArrayList<>();
listaDettaglioDecretoSingolo = new ArrayList<>();

for(int i = 0; i < 1022; i++){
decretoSingoloTemp = new DecretoSingoloViewObject("Roma", "ABCDE3593CXXE",
"decreto singolo", date,new BigDecimal(56000), new BigDecimal(343434),
new BigDecimal(55656), new BigDecimal(9999));

for(int j = 0; j < 111; j++){
listaDettaglioDecretoSingolo.add(new DettaglioDecretoSingoloViewObject(22,
date, "numero dec pag",
"tipo pag", new BigDecimal(45),
"nota dec"));
}
decretoSingoloTemp.setDetails(listaDettaglioDecretoSingolo);
listaDecretoSingolo.add(decretoSingoloTemp);
}
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String jsonList = null;
jsonList = ow.writeValueAsString(listaDecretoSingolo);

我想测试上面这段代码的速度。但是,当我运行它并尝试将列表转换为 JSON 字符串时,我收到此异常:

at com.fasterxml.jackson.core.util.TextBuffer.carr(TextBuffer.java:703) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.util.TextBuffer.expand(TextBuffer.java:664) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.util.TextBuffer.append(TextBuffer.java:455) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.io.SegmentedStringWriter.write(SegmentedStringWriter.java:67) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator._flushBuffer(WriterBasedJsonGenerator.java:1910) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.writeRawLong(WriterBasedJsonGenerator.java:496) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.writeRaw(WriterBasedJsonGenerator.java:430) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.util.DefaultPrettyPrinter$Lf2SpacesIndenter.writeIndentation(DefaultPrettyPrinter.java:472) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.util.DefaultPrettyPrinter.beforeObjectEntries(DefaultPrettyPrinter.java:265) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator._writePPFieldName(WriterBasedJsonGenerator.java:297) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator._writeFieldName(WriterBasedJsonGenerator.java:227) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.core.json.WriterBasedJsonGenerator.writeFieldName(WriterBasedJsonGenerator.java:116) [jackson-core-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:539) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:644) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:100) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:21) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:183) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:541) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:644) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:100) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:21) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:183) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:114) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:809) [jackson-databind-2.3.3.jar:2.3.3]
at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:684) [jackson-databind-2.3.3.jar:2.3.3]
at it.istruzione.hp.scuoleSicure.controller.ConsultaPagamentiController.ricercaConsultaImpegni(ConsultaPagamentiController.java:116) [classes:]
at it.istruzione.hp.scuoleSicure.controller.ConsultaPagamentiController$$FastClassBySpringCGLIB$$8a5debc0.invoke(<generated>) [spring-core-4.0.5.RELEASE.jar:]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.0.5.RELEASE.jar:4.0.5.RELEASE]

当列表尺寸较小时(例如 10、20、30..),我不会收到此错误。但是,当我增加大小,接近数千或更少时,我遇到了这个问题......

有什么办法可以解决吗?

最佳答案

您正在创建大量对象,因此需要大量内存。尝试使用 -Xmx 选项来增加最大堆大小。

Xmx and Xms are well explained here.

关于java.lang.OutOfMemory错误: Java heap space with JSON conversion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34657372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com