Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8325089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:18:55+00:00 2026-06-09T00:18:55+00:00

I have a Tomcat webapp which does some pretty memory and CPU-intensive tasks on

  • 0

I have a Tomcat webapp which does some pretty memory and CPU-intensive tasks on the behalf of clients. This is normal and is the desired functionality. However, when I run Tomcat, memory usage skyrockets over time to upwards of 4.0GB at which time I usually kill the process as it’s messing with everything else running on my development machine:

enter image description here

I thought I had inadvertently introduced a memory leak with my code, but after checking into it with VisualVM, I’m seeing a different story:

enter image description here

VisualVM is showing the heap as taking up approximately a GB of RAM, which is what I set it to do with CATALINA_OPTS="-Xms256m -Xmx1024".

Why is my system seeing this process as taking up a ton of memory when according to VisualVM, it’s taking up hardly any at all?


After a bit of further sniffing around, I’m noticing that if multiple jobs are running simultaneously in the applications, memory does not get freed. However, if I wait for each job to complete before submitting another to my BlockingQueue serviced by an ExecutorService, then memory is recycled effectively. How can I debug this? Why would garbage collection/memory reuse differ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:18:57+00:00Added an answer on June 9, 2026 at 12:18 am

    You can’t control what you want to control, -Xmx only controls the Java Heap, it doesn’t control consumption of native memory by the JVM, which is consumed completely differently based on implementation. VisualVM is only showing you what the Heap is comsuming, it doesn’t show what the entire JVM is consuming as native memory as an OS process. You will have to use OS level tools to see that, and they will report radically different numbers, usually much much larger than anything VisualVM reports, because the JVM uses up native memory in an entirely different way.

    From the following article Thanks for the Memory ( Understanding How the JVM uses Native Memory on Windows and Linux )

    Maintaining the heap and garbage collector use native memory you can’t control.

    More native memory is required to maintain the state of the
    memory-management system maintaining the Java heap. Data structures
    must be allocated to track free storage and record progress when
    collecting garbage. The exact size and nature of these data structures
    varies with implementation, but many are proportional to the size of
    the heap.

    and the JIT compiler uses native memory just like javac would

    Bytecode compilation uses native memory (in the same way that a static
    compiler such as gcc requires memory to run), but both the input (the
    bytecode) and the output (the executable code) from the JIT must also
    be stored in native memory. Java applications that contain many
    JIT-compiled methods use more native memory than smaller applications.

    and then you have the classloader(s) which use native memory

    Java applications are composed of classes that define object structure
    and method logic. They also use classes from the Java runtime class
    libraries (such as java.lang.String) and may use third-party
    libraries. These classes need to be stored in memory for as long as
    they are being used. How classes are stored varies by implementation.

    I won’t even start quoting the section on Threads, I think you get the idea that
    -Xmx doesn’t control what you think it controls, it controls the JVM heap, not everything
    goes in the JVM heap, and the heap takes up way more native memory that what you specify for
    management and book keeping.

    Plain and simple the JVM uses more memory than what is supplied in -Xms and -Xmx and the other command line parameters.

    Here is a very detailed article on how the JVM allocates and manages memory, it isn’t as simple as what you are expected based on your assumptions in your question, it is well worth a comprehensive read.

    ThreadStack size in many implementations have minimum limits that vary by Operating System and sometimes JVM version; the threadstack setting is ignored if you set the limit below the native OS limit for the JVM or the OS ( ulimit on *nix has to be set instead sometimes ). Other command line options work the same way, silently defaulting to higher values when too small values are supplied. Don’t assume that all the values passed in represent what are actually used.

    The Classloaders, and Tomcat has more than one, eat up lots of memory that isn’t documented easily. The JIT eats up a lot of memory, trading space for time, which is a good trade off most of the time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Struts2 webapp, in which I compiled using the Tomcat 5.5 libraries.
I have a Tomcat Java webapp which is thrashing the Java GC when under
I have a Tomcat 5.5 running which includes a Webapp with the Java Reporting
I have webapp which has a jdbc driver dependency. And this is dependency's scope
In my webapp which is deployed in tomcat environment, I have one spring configuration
We have a tomcat webapp which provides webservices which are protected using Spring Security.
I have a VPS on which I serve Tomcat 6.0. 500mb memory was enough,
I have a webapp running in Tomcat which uses Spring for dependency injection. (It's
I have a webapp based on Spring 3.0.6 which works fine on Tomcat 7.0.
We have a Tapestry-Spring-Hibernate webapp running on Tomcat 6, handing about a few 1000

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.