• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

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: 3968
36
  • 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: 6710
161
  • 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: 4741
50
  • 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


 
Marshal
Posts: 26128
77
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.
 
Happily living in the valley of the dried frogs with a few tiny ads.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic