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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:23:17+00:00 2026-05-26T12:23:17+00:00

What strategies should be employed to ensure that JVM memory management is always quick?

  • 0

What strategies should be employed to ensure that JVM memory management is always quick?

I run a method periodically, every 10 seconds, via Timer#scheduleAtFixedRate() and the periodic method takes 5 to 50 milliseconds usually but occasionally much longer. The application does not have anything else to do but this periodic method. Sometimes it exceeds 10 seconds. Since the nature of the application does not or should not cause large variability in the elapsed time, I think the variability is due to garbage collection. How can I keep garbage collection well under 10 seconds always?

The periodic method builds up lists and plots points on graphs every 10 seconds for several hours. At the end of the several hour period it does some binary serializations of all data that was collected the whole time.

I tried ending the periodic method with a System.gc() but I still get method runs that take more than 10 seconds. After the 10 second run, it will go back to 5 millisecond elapsed time method runs. Then it will gradually take longer, until there is an elapsed time of about 10 seconds. Then the cycle repeats. I’ve seen other patterns as well.

You might wonder what happens if the method takes longer than the period that is set in scheduleAtFixedRate(). What happens is that the next invocation is delayed (there is no aborting of an in progress method nor an attempt to stick to the schedule by using another thread). If slow runs persist I guess there would simply be a big backlog. Fortunately the long elapsed time runs are just occasional and the majority are just between 5 and 50 milliseconds. Still, I don’t want these long elapsed time runs because they ruin the periodicity.

A quick fix is to change my period to 15 seconds, thereby ensuring the period is greater than the worst case elapsed time. This would only be a work-around. It would be far better to get consistency in garbage collection.

  • 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-05-26T12:23:18+00:00Added an answer on May 26, 2026 at 12:23 pm

    To reduce elapsed times by trading off efficiency use the JVM option -Xincgc on your java invocation command line.

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

Sidebar

Related Questions

The Celery docs section Performance and Strategies suggests that tasks with multiple 'steps' should
I often see two conflicting strategies for method interfaces, loosely summarized as follows: //
Looking for some branching strategies for a situation that has come up for a
I realize that in general, you should not store user credentials directly (i.e., in
I have an Android application that uses the well known Strategies for Legacy Applications
I am on creating a system, I am trying to ensure that user cannot
Does anyone have any strategies/tips/traps for moving to Team System? Should it be done
I was recently reading this document which lists a number of strategies that could
To start off, I'm not that great with database strategies, so I don't know
Possible Duplicate: What strategies have you used to improve build times on large projects?

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.