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 8113967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:00:06+00:00 2026-06-06T03:00:06+00:00

I have a java program that performs 5 different tasks. When I run the

  • 0

I have a java program that performs 5 different tasks. When I run the program with -Xmx512m memory parameter, tasks 1-4 run fine but task 5 goes out of memory. When I run the program with -Xmx1024m, all 5 tasks runs fine but tasks 1-4 that previously ran fine with 512m heap now uses up almost all of 1024m heap. The same thing happens if I use -Xms128m -Xmx1024m.

What would be the memory parameters to instruct JVM to keep the memory utilization low (e.g. 512m for tasks 1-4) and only to use more memory when actually needed (e.g. in case of task 5)?

Maybe I need a way to activate the garbage collector more frequently than the default setting?

  • 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-06T03:00:08+00:00Added an answer on June 6, 2026 at 3:00 am

    I think you have a misunderstanding on how the JVM works. This is not a GC issue or a “task” issue.

    Your tasks have memory leaks or they are designed to hold onto more and more memory.

    -Xmx1024m sets the maximum memory the JVM can allocate. It’d be the same thing as if you only have 1024 megs of physical memory and no virtual memory.

    It would be helpful to update your question with the definition of Task. Are these 5 separate JVM’s? Or just 5 units of work in a single JVM.

    Update

    I don’t intend the program to use all 1g heap always. My intention is to instruct the JVM to use 512m heap if can manage and to use more memory only if required. When the memory is no more required, to fall back to 512m or even less amount of memory.

    Just because you set -Xmx1024m does not mean the JVM WILL use all that memory. It’s just a max limit. Setting Xms till set a minimum amount of memory to be used. Your program ultimately determines the running amount of memory being utilized. If it hits the limit set by -Xmx then it will throw an OutOfMemoryError

    You can suggest to the JVM to run the Garbage Collector by invoking System.gc(). Notice I said suggest, you cannot force the GC to run. You could be running on a platform that refuses to even do GC. You also need to look into what GC algorithm it is choosing for your application. I would look here Tuning Garbage Collector.

    If you need such fine grain controls over memory usage you will need to pick something else besides the JVM.

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

Sidebar

Related Questions

I have a Java program that runs many small simulations. It runs a genetic
I have a java program that will work with a variety of Java Beans.
I have a Java program that executes from Spring Qquartz every 20 seconds. Sometimes
I have a Java program that is launched by a batch file with a
I have a Java program that generates Java classes for my application. Basically it
I have a Java program that opens a file using the RandomAccessFile class. I'd
I have a Java program that is supplied a directory name, gets a list
I have a Java program that connects to a webserver using SSL/TLS, and sends
I have a Java program that runs on my Ubuntu 10.04 machine and, without
I have a java program that connects to a MySql database and it's working

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.