简体   繁体   中英

java.lang.OutOfMemoryError: Java heap space with 300MB java.exe cap

I have a web based applications that runs on tomcat5 mysql and using JVM and java etc... it works fine but everytime it starts getting up to around 300MB of memory for the java.exe (windows server ) it will crash when doing a query or anything that takes up any space in ram at all. But the machine server itself has 16GB of ram....

How can this be overcome?

The error I'm getting is like:

ERROR resultset Exception in processing the request (4) : java.lang.OutOfMemoryError: Java heap space

and if I kill task java.exe and restart the process it works again until java.exe hits some 300MB memory wall.... I have already tried setting xmx to something like 1600MB or larger but to no avail and made no difference at all....

anyone know what is going on?

///////////////

UPDATE WITH COMMENTS

okay there is something wierd I figured out, if I set it to anything at or below 1024 mb it works and the services start in services.msc on window server all versions. but if I set it to anything more, even at 1025mb, it will not start up, UNLESS I do exact multiples of 24, like 1024, 1048, 1072 etc... this holds until it reaches a limit...

On a windows server 2008 32bit that only has 4GB total, the limit is around ~1600-ish but suprisingly on a windows server 2008 r2 64bit with tons of memory, the limit was only around ~1200

This is the exact same tomcat5.exe and tomcat5w.exe and installed as service with exact same way... so it makes no sense whatsoever....

Why does memory increase past the 1024mb mark need to be in precise 24 mb increments? and why is there a different "wall", with the LOWER spec'd machine able to reach much higher (1600mb) than the higher spec'd one with more ram (~1200)

I read something about JVM needing contingious memory but this is just nuts and doesn't make any sense whatsoever

As you only mention "tomcat5" (not even 5.5): Please note that the last version of Tomcat 5.0 was released in 2004, but even if you're referring to Tomcat 5.5, that's been end-of-lifed in 2012. Tomcat 5 was based on Java5, and this is where I'm looking for the culprit:

(Note, this has been long time ago, and I'm paraphrasing what I still remember from that time. I might only hit the proper direction, but not every detail)

Back in those times, 32bit Java VMs were more common than they are today, and 32bit processes on 32bit Windows typically suffer from one problem: They need contiguous memory blocks - the absolute maximum that can be provided to a 32bit process (but only when memory hasn't yet been fragmented) was somewhere around 1.5G - no matter how much memory the machine had.

My general recommendation is to set -Xmx and -Xms to the same values. Allocate whatever you're prepared to allocate right at the start - you'll need to be prepared to have it anyways, and there's no need to wait for an arbitrary event that triggers OutOfMemory conditions. Maybe your application can get along with 300 or 400 MB, but tries to allocate more, because you've allowed it to do so with a -Xmx value larger than what the system can provide. You rather want to detect this condition when you start the process (eg when you're sitting next to the computer) rather than Sunday night at 3am, when the service stops.

In case you have any 32bit component in your system, fix this first, then try again. You might also want to prioritize upgrading to an environment where you can get upgrades and current knowledge, rather than falling behind for more than a decade (or even more than half a decade, depending on the actual version you're running).

there is not a lot of information about your app - but if I understand it right, and you run it on the standalone Tomcat server, you should set memory configuration for Tomcat via the configuration file. Here you can find a description - https://www.programmergate.com/tomcat-memory-usage/

set JAVA_OPTS=-Dfile.encoding=UTF-8 -Xms128m -Xmx2048m -XX:PermSize=265m -XX:MaxPermSize=1024m

If you are using something like Spring Boot or another self-executable technique, please add it to the description.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM