views:

71

answers:

3

Is it possible to get a notification when a long GC cycle occurs?

I'd like to write to our specific log when this happens.

+3  A: 

Maybe not within the jvm, but you can start Java with the -verbose:gc option, this should create console output like [GC 511K->105K(1984K), 0.0029585 secs]. [1]

With some clever scripting you then can build an alert system on long GC cycles.

Andreas_D
Yeah, I was just reading that here http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html , section 3.2 has good information about this.
amischiefr
I was looking for a quick solution from within the JVM, don't feel like messing with 'clever scripting' :)
ripper234
There is no build in way (that I am aware of), you could use something like VisualVM to monitor it.
amischiefr
A: 

There is a possibility to log the activity of the garbage collector using JMX. Typically it is used to monitor the performance of large-scale java applications. Maybe this solution is a bit too full-blown for your needs but at least you would be able to monitor what the gargabe collector does.

JConsole is a nice littel tool that makes use of JMX to display some performace data.

zlajo
A: 

I guess you could poll the GarbageCollectorMXBean and look out for the collection time jumping up.

mlk