Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File upload using Tomcat6.0 gives java.lang.OutOfMemoryError: Java heap space[/b]

Vijay Kumar Raman
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to upload file (size 1MB to 100MB) through my web application running in Tomcat 6 and ultimately storing the file in a database table column using hibernate 3.0 as BLOB data in MySQL database. I am able to upload and save files of size upto 10MB successfully (Though I get the same OutofMemory error). But when I try to upload and save file of size more than 10 MB, I am getting below Error message,

Caused by: java.lang.OutOfMemoryError: Java heap space
at com.mysql.jdbc.Buffer.<init>(
at com.mysql.jdbc.MysqlIO.readRemainingMultiPackets(
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(
at com.mysql.jdbc.MysqlIO.checkErrorPacket(
at com.mysql.jdbc.MysqlIO.checkErrorPacket(
at com.mysql.jdbc.MysqlIO.nextRow(
at com.mysql.jdbc.MysqlIO.readSingleRowSet(
at com.mysql.jdbc.MysqlIO.getResultSet(
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(
at com.mysql.jdbc.MysqlIO.readAllResults(
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(
at com.mysql.jdbc.ConnectionImpl.execSQL(
at com.mysql.jdbc.PreparedStatement.executeInternal(
at com.mysql.jdbc.PreparedStatement.executeQuery(
at org.hibernate.jdbc.AbstractBatcher.getResultSet(
at org.hibernate.loader.Loader.getResultSet(
at org.hibernate.loader.Loader.doQuery(
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(
at org.hibernate.loader.Loader.doList(
at org.hibernate.loader.Loader.listIgnoreQueryCache(
at org.hibernate.loader.Loader.list(
at org.hibernate.loader.hql.QueryLoader.list(
at org.hibernate.hql.ast.QueryTranslatorImpl.list(
at org.hibernate.engine.query.HQLQueryPlan.performList(
at org.hibernate.impl.SessionImpl.list(
at org.hibernate.impl.QueryImpl.list(

The max_allowed_packet size in MYSQL is 1GB and I tried changing the heap size in tomcat console as set CATALINA_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m" and JAVA_OPTS="-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m". Also I explicitly added catalina.bat and files in tomcat/bin folder with the same CATALINA_OPTS and JAVA_OPTS values.

On executing the application in tomcat the uploaded file is correctly copied into D:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\<MyApp> folder and the logging statment is written upto object ref) method in data layer.

PS: The same application executed as standalone application using main method uploads file of size 120MB successfully without throwing any error.

Kindly help. Thanks.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic