Results 1 to 6 of 6
  1. #1
    kulkarni_ash is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default Is there a hook i can add to JVM so it would print log when reaches 70% of memory

    Hi
    Is there any hook i can attach to a JVM process so it can log when it reaches 70% of total memory,
    I can use code like below to get memory information, but this is kind of on demand, is there a way i can get memory information by event or some thing

    Java Code:
    Runtime runtime = Runtime.getRunTime();  
    runtime.totalMemory();

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    16

    Default Re: Is there a hook i can add to JVM so it would print log when reaches 70% of memory

    You could create a thread that periodically checks the memory usage and prints a message when it goes over your threshold.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    kulkarni_ash is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default Re: Is there a hook i can add to JVM so it would print log when reaches 70% of memory

    I was looking on lines of java.lang.management.MemoryPoolMXBean

  4. #4
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    7

    Default Re: Is there a hook i can add to JVM so it would print log when reaches 70% of memory

    Had a chance to look through MemoryPoolMXBean (Java Platform SE 7 )? It has sample code for usage threshold notifications.
    Last edited by jashburn; 04-29-2014 at 02:18 AM. Reason: Fix typo

  5. #5
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: Is there a hook i can add to JVM so it would print log when reaches 70% of memory

    To piggyback off of this thread - is there any chance somebody could chat a bit about what threads actually are? I've begun using them, but I haven't gotten what they do fundamentally. Why and how is a thread useful in this situation?

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    13

    Default Re: Is there a hook i can add to JVM so it would print log when reaches 70% of memory

    Answer yourself this: if you don't use a thread to fulfill the requirement, what would your application be doing? Waiting until it is time to check again, if you use only a single thread then you can do only one thing at once after all. Better let a thread/timer handle the "periodically checking" part.

    There are many more reasons to use threading, but Google/Wikipedia can answer that just fine.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. How I can hook the keyboard?
    By SSaAA in forum New To Java
    Replies: 3
    Last Post: 06-10-2012, 02:51 PM
  2. Replies: 0
    Last Post: 05-26-2012, 10:18 PM
  3. How to hook into another Java application's thread?
    By mnpeep in forum Advanced Java
    Replies: 2
    Last Post: 03-06-2012, 12:41 AM
  4. Long wait time before print job reaches printer
    By Astghik in forum AWT / Swing
    Replies: 0
    Last Post: 01-12-2010, 11:29 AM
  5. Need to hook up my jsp code to third party vendor
    By priya123 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-28-2008, 11:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •