• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Usage of Verbose:gc JVM options

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

Can any one tell how to monitor JVM heap size usage?

As per my understanding if I write a class A, and it requires a large
amount of memory, it's possible that the virtual machine will begin to
throw OutOfMemoryError instances when attempting to instantiate objects

In such case we can increase the "heap size" allocated by the Java
Virtual Machine (JVM) by using command line options.

But is there any mechanism we monitor the heap size, so that we could
be noted before this out Of memory error occurs?

and also I came to know about verbose:gc command. Can anyone tell me how to use this option from console.

Can anyone tell in detail with example.

Thanks and regards,
Swetha
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But is there any mechanism we monitor the heap size, so that we could
be noted before this out Of memory error occurs?



If you want to know the amount of free memory, you can use:

Runtime.getRuntime().freeMemory()

However, relying on this method for identifying the chances of OutOfMemory errors may not be appropriate.

and also I came to know about verbose:gc command. Can anyone tell me how to use this option from console.



You can use:



If you need more detailed garbage collection logs, have a look at:

How to enable garbage collection logs
 
Swetha M.S
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I tried using your instructions. Its working exactly like what I wanted.

But the problem is, I have an application in production, that uses ANT build scripts and JBoss.

Now I was asked to monitor JVM heap sizes.

I usually use eclipse IDE and get war and ear and then deploy.

Where should I give the JVM option verbose:gc so that I can get the heap size tracked on logfiles.

Can you please help me.

Thanks,
Swetha
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your application is deployed on JBoss and JBoss is started using the run.bat file. You will have to edit this run.bat file to contain something like:
 
Swetha M.S
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks a lot!! Its working fine.
Another small info needed. You have told about the GC logs creation in the previous mail.

But can you please tell how to configure those logs using log4j.xml.

I need those logs in a separate file.

Thanks in advance
Swetha
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think thats possible using log4j, since those are system level logs. However if you want to log those messages to a specific file, you can still do it without using log4j using -Xloggc:D:/log/myLogFile.log where myLogFile.log will contain the logs. This is mentioned in the link that i posted earlier in this thread.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic