java.lang.OutOfMemoryError: Java heap space
 package com.shopping.view.app.action;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.shopping.core.annotation.SecurityMapping;
import com.shopping.foundation.domain.GoodsBrand;
import com.shopping.foundation.domain.GoodsClass;
import com.shopping.foundation.service.IGoodsBrandService;
import com.shopping.foundation.service.IGoodsClassService;

@Controller
public class APIGoods_listAction {

    @Autowired
    private IGoodsBrandService goodsBrandService;
    @Autowired
    private IGoodsClassService goodsClassService;

    @RequestMapping(value="/api/goods_list.htm",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String goods_list(HttpServletResponse response) {
        List<GoodsBrand> gbs = this.goodsBrandService.query("select obj from GoodsBrand obj order by obj.sequence asc", null, -1,
                -1);
    //  List<GoodsClass> gcs = this.goodsClassService.query(
        //      "select obj from GoodsClass obj where obj.parent.id is null order by obj.sequence asc", null, -1, -1);
         response.setContentType("text/json");
         response.setHeader("Cache-Control", "no-cache");
         response.setCharacterEncoding("UTF-8");
         if(gbs!=null && gbs.size()>0){
             String data = Json.toJson(gbs, JsonFormat.compact());
             return "{\"statusCode\":200,\"msg\":\"加载成功!\",\"data\":"+data+"}";
         }else{
             return "{\"statusCode\":500,\"msg\":\"系统错误!\"}";
         }
    }

}
 六月 12, 2017 5:15:12 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [shopping] in context with path [/shopping] threw exception [Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space] with root cause
java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3332)
    at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)
    at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:622)
    at java.lang.StringBuilder.append(StringBuilder.java:202)
    at org.nutz.lang.stream.StringWriter.write(StringWriter.java:23)
    at java.io.Writer.write(Writer.java:113)
    at java.io.Writer.append(Writer.java:293)
    at org.nutz.json.JsonRendering.string2Json(JsonRendering.java:237)
    at org.nutz.json.JsonRendering.appendName(JsonRendering.java:55)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:71)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:192)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:273)
    at org.nutz.json.JsonRendering.coll2Json(JsonRendering.java:297)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:269)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:73)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:192)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:273)
    at org.nutz.json.JsonRendering.coll2Json(JsonRendering.java:297)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:269)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:73)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:192)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:273)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:73)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:192)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:273)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:73)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:192)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:273)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:73)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:192)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:273)

3个回答

你用的json转化的是第三方的吗?应该是这个转化有内存限制吧。

内存溢出了,可以百度一下,设置一下memory的大小,如果还不够的话,就看一下哪里一次读入太多的数据,是否可以分批次读取

return "{\"statusCode\":200,\"msg\":\"加载成功!\",\"data\":"+data+"}";

这句代码中的data太大了,导致进行‘+’拼接操作时,扩容,超过了当前设置的内存。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐