• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Facing java.lang.OutOfMemoryError: Java heap space when reading and writing large data

 
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to read and large data . But I face java.lang.OutOfMemoryError: Java heap space.How can I write file little by little by seperating ? Thanks in advance .
 
Rancher
Posts: 3523
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain what the program is doing?  How is it reading and writing files?
Does it try to read all of a very large file into memory?

Have you tried using the java command's options to set heap size larger?


Can you make a small, complete (SSCCE) program that shows the problem?
 
Miri Yusifli
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:Can you explain what the program is doing?  How is it reading and writing files?
Does it try to read all of a very large file into memory?

Have you tried using the java command's options to set heap size larger?


Can you make a small, complete (SSCCE) program that shows the problem?



I try to save video file and image files to my server . I am using Spring MVC . When I use small files everything is okay , but file above20-30 mb I face outOfmemoryException
 
Saloon Keeper
Posts: 5868
147
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Have you tried using the java command's options to set heap size larger?


From this topic I take it that the JVM in question is part of a shared hosting setup, and so the JVM options like heap size can't be changed.
 
Rancher
Posts: 4315
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the code where you read the input stream and write to the output stream for these files?
 
Miri Yusifli
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Can you show the code where you read the input stream and write to the output stream for these files?


This is my upload method , I think that I should save it as many chunks
 
Miri Yusifli
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Miri Yusifli wrote:I want to read and large data . But I face java.lang.OutOfMemoryError: Java heap space.How can I write file little by little by seperating ? Thanks in advance .



I solved my problem ) This my last metthod


 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That looks like it could be very useful for others with the same kind of problem. I gave you a cow for posting it.
 
You showed up just in time for the waffles! And this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!