• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Giving memory for methods like allocating memory for micro services

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I saw in many java application, when a user performs a particular task the out of memory exception occured.

Assume i have given 4 GB of RAM for application...However i want to force a condition to the application that each method or process should not take more than 100MB

If it reaches 100 MB, the function should get terminated...Now when a single method takes 4 GB gradually the system crashes

Lot of Spring and Java improvements are done....Wondering why the memory allocation for a particular method or process cannot be done in Java?

Please advise what would be the best approach or way to allocate memory  for a method or process etc..

Thanks
 
Marshal
Posts: 76881
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has Java┬« ever supported separate memory allocation for a method? Wouldn't that be stack space, in which case the method would go wrong with a stack overflow error. The whole idea of an automatic heap is to change memory management from the user's problem to the JVM's problem. You get an out of memory error when  you retain more “live” references to objects than there is heap space to accommodate them all.

Moving to the “general” forum because this question is too hard for “beginning”.
 
Joseph Michael
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand java doesn't support separate memory allocation for a method. My question is why it is not allocated even as a configured one.. Instead of whole application gets crashed, they Java can come up with memory allocation i.e max for a function to get executed. Everytime when there is a enterprise application crash. We need to bring down the whole application down instead of killing one particular process.
 
Sheriff
Posts: 27460
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joseph Michael wrote:Everytime when there is a enterprise application crash. We need to bring down the whole application down instead of killing one particular process.



Let's take this as your actual question, since even the idea that a "process" (meaning, I assume, some code in a JVM) owns some memory conflicts with how Java works. You would like ideas about how to implement that requirement.
 
Joseph Michael
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Paul Calpham, I would like ideas about how to implement that requirement. Please kindly share your thoughts on this.
 
Paul Clapham
Sheriff
Posts: 27460
88
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joseph Michael wrote:Yes Paul Calpham, I would like ideas about how to implement that requirement. Please kindly share your thoughts on this.



It's very common for web applications to be at risk for that problem. Any time a servlet uses up all of the memory and throws an OutOfMemory exception, the whole application goes down and has to be restarted. I've been responsible in the past for web applications in which that happened.

And yet millions of Java web applications are running at this very moment doing their work. That suggests that there's a lot of people around who don't feel this is a pressing problem for them.

So, if this is a pressing problem for you and you have code which is eating up all of the app's memory, then your first step should be to stop it from doing that. Post the guilty code and we can discuss it.

However if it's not an issue you are having now then I don't think there's much point in considering how to figure out difficult workarounds to solve a problem you aren't having.
 
Joseph Michael
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul Clapham, one example is we provide search feature to the customer...Few mistakenly searched with % multiple or single times. With huge DB, the application doesn't respond and leads to out of memory exception....Still it has to wait for a long time to get back the results.
 
Paul Clapham
Sheriff
Posts: 27460
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, we had that too. It does take a lot of time to extract data from a database and use up all of the JVM's memory. But I don't see why restricting the memory available to that particular process is going to help, except that the user doesn't have to wait as long for it to crash I suppose.
 
machines help you to do more, but experience less. Experience this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic