NutzCN Logo
问答 大字符串插入内存溢出
发布于 2647天前 作者 threefish 2545 次浏览 复制 上一个帖子 下一个帖子
标签:

首先是错误日志

java.lang.OutOfMemoryError: Java heap space

	at java.util.Arrays.copyOf(Arrays.java:3332)
	at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
	at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:448)
	at java.lang.StringBuffer.append(StringBuffer.java:270)
	at org.apache.log4j.helpers.PatternParser$LiteralPatternConverter.format(PatternParser.java:420)
	at org.apache.log4j.PatternLayout.format(PatternLayout.java:502)
	at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:302)
	at org.apache.log4j.WriterAppender.append(WriterAppender.java:160)
	at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
	at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
	at org.apache.log4j.Category.callAppenders(Category.java:206)
	at org.apache.log4j.Category.forcedLog(Category.java:391)
	at org.apache.log4j.Category.log(Category.java:856)
	at org.nutz.log.impl.Log4jLogAdapter$Log4JLogger.log(Log4jLogAdapter.java:113)
	at org.nutz.log.impl.AbstractLog.log(AbstractLog.java:50)
	at org.nutz.log.impl.AbstractLog.debug(AbstractLog.java:103)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:20)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:55)
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:149)
	at com.yh.app.webser.module.DaoTest.testInsert(DaoTest.java:66)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

说明 字符串 test111.txt 大小 4812kb
发生错误的测试代码

 ReportTask task=new ReportTask();
        task.setExcelJson(FileUtil.readFile("d://test//test111.txt"));
        dao.insert(task);

使用JDBC写法没有报错

String strsql = "INSERT INTO reporttask (`excelJson`) VALUES (?);";
            PreparedStatement stmt = conn.prepareStatement(strsql);
            stmt.setString(1, FileUtil.readFile("d://test//test111.txt"));
            System.out.println(stmt.executeUpdate());
3 回复

看来这个字段要存文件了

日志太长了?

嗯,应该是日志文件的原因

添加回复
请先登陆
回到顶部