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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:06:47+00:00 2026-05-15T10:06:47+00:00

Can the JVM recover from an OutOfMemoryError without a restart if it gets a

  • 0
  1. Can the JVM recover from an OutOfMemoryError without a restart if it gets a chance to run the GC before more object allocation requests come in?

  2. Do the various JVM implementations differ in this aspect?

My question is about the JVM recovering and not the user program trying to recover by catching the error. In other words if an OOME is thrown in an application server (jboss/websphere/..) do I have to restart it? Or can I let it run if further requests seem to work without a problem.

  • 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-15T10:06:48+00:00Added an answer on May 15, 2026 at 10:06 am

    It may work, but it is generally a bad idea. There is no guarantee that your application will succeed in recovering, or that it will know if it has not succeeded. For example:

    • There really may be not enough memory to do the requested tasks, even after taking recovery steps like releasing block of reserved memory. In this situation, your application may get stuck in a loop where it repeatedly appears to recover and then runs out of memory again.

    • The OOME may be thrown on any thread. If an application thread or library is not designed to cope with it, this might leave some long-lived data structure in an incomplete or inconsistent state.

    • If threads die as a result of the OOME, the application may need to restart them as part of the OOME recovery. At the very least, this makes the application more complicated.

    • Suppose that a thread synchronizes with other threads using notify/wait or some higher level mechanism. If that thread dies from an OOME, other threads may be left waiting for notifies (etc) that never come … for example. Designing for this could make the application significantly more complicated.

    In summary, designing, implementing and testing an application to recover from OOMEs can be difficult, especially if the application (or the framework in which it runs, or any of the libraries it uses) is multi-threaded. It is a better idea to treat OOME as a fatal error.

    See also my answer to a related question:

    EDIT – in response to this followup question:

    In other words if an OOME is thrown in an application server (jboss/websphere/..) do I have to restart it?

    No you don’t have to restart. But it is probably wise to, especially if you don’t have a good / automated way of checking that the service is running correctly.

    The JVM will recover just fine. But the application server and the application itself may or may not recover, depending on how well they are designed to cope with this situation. (My experience is that some app servers are not designed to cope with this, and that designing and implementing a complicated application to recover from OOMEs is hard, and testing it properly is even harder.)

    EDIT 2

    In response to this comment:

    "other threads may be left waiting for notifies (etc) that never come" Really? Wouldn’t the killed thread unwind its stacks, releasing resources as it goes, including held locks?

    Yes really! Consider this:

    Thread #1 runs this:

        synchronized(lock) {
             while (!someCondition) {
                 lock.wait();
             }
        }
        // ...
    

    Thread #2 runs this:

        synchronized(lock) {
             // do something
             lock.notify();
        }
    

    If Thread #1 is waiting on the notify, and Thread #2 gets an OOME in the // do something section, then Thread #2 won’t make the notify() call, and Thread #1 may get stuck forever waiting for a notification that won’t ever occur. Sure, Thread #2 is guaranteed to release the mutex on the lock object … but that is not sufficient!

    If not the code ran by the thread is not exception safe, which is a more general problem.

    "Exception safe" is not a term I’ve heard of (though I know what you mean). Java programs are not normally designed to be resilient to unexpected exceptions. Indeed, in a scenario like the above, it is likely to be somewhere between hard and impossible to make the application exception safe.

    You’d need some mechanism whereby the failure of Thread #1 (due to the OOME) gets turned into an inter-thread communication failure notification to Thread #2. Erlang does this … but not Java. The reason they can do this in Erlang is that Erlang processes communicate using strict CSP-like primitives; i.e. there is no sharing of data structures!

    (Note that you could get the above problem for just about any unexpected exception … not just Error exceptions. There are certain kinds of Java code where attempting to recover from an unexpected exception is likely to end badly.)

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

Sidebar

Related Questions

How does JVM type erasure help Clojure? Can Clojure exist without it? What would
Since all java applications are run eventually by the JVM, why can't the JVM
Can a LINQ enabled app run on a machine that only has the .NET
I know that a custom JVM can behave a little differently, and I'm trying
According to Brian Goetz's Java Concurrency in Practice JVM can't exit until all the
Can I use jmap to create a java memory heap on a JVM which
how can I show pictures in WebView without saving images into file system? I
If all tables I want to delete from have the column gamer_id can i
How can I set target JVM version in SBT? In Maven (with maven-scala-plugin) it
How can I use other JVM languages (ie. Scala) with Apache Tomcat?

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.