This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes File upload using Tomcat6.0 gives java.lang.OutOfMemoryError: Java heap space[/b] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "File upload using Tomcat6.0 gives java.lang.OutOfMemoryError: Java heap space[/b]" Watch "File upload using Tomcat6.0 gives java.lang.OutOfMemoryError: Java heap space[/b]" New topic
Author

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

Vijay Kumar Raman
Greenhorn

Joined: Oct 19, 2010
Posts: 12
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>(Buffer.java:59)
at com.mysql.jdbc.MysqlIO.readRemainingMultiPackets(MysqlIO.java:3135)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3089)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2991)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3532)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1441)
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2936)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:477)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2631)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1800)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2221)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)

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 catallina.sh 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 session.save(hibernatepojo 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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: File upload using Tomcat6.0 gives java.lang.OutOfMemoryError: Java heap space[/b]
 
Similar Threads
java.lang.OutOfMemoryError: Java heap space
OutOfMemory Error with MySQL 5 and / or Tomcat
Out of Memory Issues with Tomcat on Ubuntu 10
issue while server startup
Java Heap Space