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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:51:14+00:00 2026-05-29T10:51:14+00:00

I have developed an application with Spring. I’ve a bean to create a thread,

  • 0

I have developed an application with Spring. I’ve a bean to create a thread, but during the execution of this thread, at runtime, the JVM throws the OutOfMemoryError – Java Heap Space.
What I would ask is whether the following solution might be suitable to solve the problem:
Once thrown the thread dies and frees the memory previously occupied by the thread, then I through another thread (which I call RestartThread), I realize that the thread is dead (without catching the error), then:
1) call Garbage Collector, that effectively frees the memory of the dead thread;
2) call back function run() of died Thread, that restart the previous instance (including private variables used by the died Thread, which remain in memory even after the generation of ‘OutOfMemoryError’) of the died Thread.

What do you think of this thing, it could create problems? Is a correct solution to restart previous istance of died Thread?

Thanks in advance,
–Alucard

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

    Recovering from an OutOfMemoryError, especially in a multi-threaded environment, is very difficult, and often even impossible. You probably should be finding out why you run out of memory (like leaking references or your application simply needs more memory than you’ve given to it) and try to fix it, rather than trying to recover from it.

    Even if you could just let the thread throwing the error die and restart it, the restarted thread would probably just die again right at the beginning. In a more worse scenario, the root cause could be in some other part of the program. This would mean that other threads in your application would start throwing the same error, as they’d be trying to allocate new objects, resulting in the error cascading all through your application and finally the whole thing would come crashing down spectacularly.

    The memory isn’t your only problem. Your application state can be pretty much anything (ie. inconsistent), if the thread terminated by an OOME was in the middle of processing and touched the state(s) of some shared object(s), which other threads also use. Also, if another thread was waiting for some monitor (mutex) the terminated thread was holding, or similar (wait/notify etc), the other thread could become deadlocked. In most cases writing the recovery logic and checking that the recovery was successful will be very difficult, as there are far too many variables and things to check before you can be sure the application has REALLY recovered.

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

Sidebar

Related Questions

Hi have this j2ee web application developed using spring framework. I have a problem
I have a web application developed with Spring 2.5. The application has numerous controllers,
I have used spring framework 3 for my application. Everything is ok while developed
I have developed a Java EE web application. This application allows a user to
I have developed a desktop database application. But the interface is not rich. So
I have developed an application to find the user's location using GPS. In this
Currently I have developed one application on android 2.3 platform. But when i test
I have developed an application with Spring MVC that deals with bulk data insert/update.
I have developed application for drawing some shapes (lines mostly) , now i need
I have developed the application in which i want to set the background color

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.