• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.OutOfMemory

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sometimes i get an error caused by the OutOfMemory-error and when i do another request to Tomcat (with smaller amount of data and thus also memory) i get no error anymore (so without restart of Tomcat).
Sometimes i get an error caused by the OutOfMemory-error and can't do a thing because i get always error caused by The OutOfMemory-error.

What's the logic between these cases? Is there a solution to prevent Tomcat for going out of memory (e.g. when you do a tomcat-startup with -Xmx512m and then tell Tomcat he isn't allowed to take new requests - a new request is definied as request of a new browser - if he's using 500m, or something like that)?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect that what happens is:
In case 1 the error in the requst Thread was caught and Tomcat managed to recover memory used by the request and was thus able to continue.
In case 2 Tomcat was not able to recover the memory.

The solution is generally proper programming technique that avoids "memory leaks" and algorithms that try to do too much in one request. Database operations that return a gazillion results for example.

In server.xml you can configure the number of connections that Tomcat will accept, etc.

Bill
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
I suspect that what happens is:
In case 1 the error in the requst Thread was caught and Tomcat managed to recover memory used by the request and was thus able to continue.
In case 2 Tomcat was not able to recover the memory.

The solution is generally proper programming technique that avoids "memory leaks" and algorithms that try to do too much in one request. Database operations that return a gazillion results for example.

In server.xml you can configure the number of connections that Tomcat will accept, etc.

Bill



Thanks for the reply.

I have been profiling this web-app and no memory leaks where found. And problem is: initial request must gain a lot of info from a database table so an image could be generated, there is no other solution for (as i see it of course)
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow - so your image generation program needs hundreds of megabytes?
Here are the thoughts that occur to me just off the wall...
JDBC query related objects are bulky - can you extract the data to a more compact form (maybe even a temp file) and make sure all the JDBC objects are closed and gc-ed before you start generating the image.
You can control the number of instances of the rendering class (possibly even make it a singleton) to prevent a large number of requests causing the memory error.
Bill
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we have spoken about my app in this thread. So we keep a lot of info in memory about our objects, to have acceptable response-times and which each new browser there are only 2 requests to database and everything that's needed is put in memory, because else it's highly inperformant (approx 1 minute to generate new map if for each request app must access database - approx 5-6 secs tot generate new map if objects are in memory)
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yeah, I remember your problem now.
Apparently throwing the out of memory error can leave your application in a state it can't recover from.
It sounds like you need a way to recognize a low memory situation and prevent new requests from being processed if there is too little free memory. What is a typical pattern of memory use - does it build up gradually or does the application have to grab a huge chunk all at once?
You could refuse a request with a "try again later" message if more than N requests are being processed or the free memory is low.

Bill
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i check the amount of free memory ?
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah - you need to get familiar with the methods in java.lang.Runtime.
We have totalMemory() maxMemory() and freeMemory() at our disposal to watch the JVM's memory use. Calls look like:

long free = Runtime.getRuntime().freeMemory();

You should probably try to get the gc to run before running the above.
Runtime.getRuntime().gc();

Bill
[ November 26, 2004: Message edited by: William Brogden ]
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i gave JVM -Xmx512m

but JVM get's the memory in small parts, so that's huge problem, because when i say that there must be at least 150 MB free to take an init-request, this condition is never fulfilled. If you know what i mean
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, why not just start it with the maximum - I think that is the
-Xms512m
command line parameter. That way you should not get the incremental free memory change, it should all be there to start with.
Bill
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that's new to me i'll try that one

Thanks. now i am gonna
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All of those command line parameters are documented in your SDK distribution - look under the ../docs/tooldocs/ directory
There are many settings there that may help with your memory problem - for example you can get a log of garbage collection events.
Bill
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added the -Xms512m option, but if i try shutting down the Tomcat server i got this error:

 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah - the thing is, executing the shutdown runs another JVM instance in order to communicate with Tomcat. If that JVM sees your environment variable with the high memory setting you run out of memory.
You need some way to execute the shutdown with a different JAVA_OPTS setting - maybe a separate set of batch files?
Bill
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
soooooooooo logical, but didn't think of that one.
Thanks for the advice
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic