wood burning stoves 2.0*
The moose likes Performance and the fly likes Usage of Verbose:gc JVM options Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Usage of Verbose:gc JVM options" Watch "Usage of Verbose:gc JVM options" New topic
Author

Usage of Verbose:gc JVM options

Swetha M.S
Greenhorn

Joined: Jul 14, 2006
Posts: 4
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
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9937
    
159

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


[My Blog] [JavaRanch Journal]
Swetha M.S
Greenhorn

Joined: Jul 14, 2006
Posts: 4
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
Marshal

Joined: Jul 20, 2005
Posts: 9937
    
159

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

Joined: Jul 14, 2006
Posts: 4
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
Marshal

Joined: Jul 20, 2005
Posts: 9937
    
159

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.
 
jQuery in Action, 2nd edition
 
subject: Usage of Verbose:gc JVM options
 
Similar Threads
dispose(), show() methods causing memory leak
JVM size
32 bit JVM memory heap issue on 64 bit XP
understanding memory usage by the VM
Can i limit memory consumed by an Objects (Aplication)