javagarbage-collectionclassloadermetaspace

In Java 8, is it possible to use JVM parameter to control when(or in what condition) to unload class?


In my JMeter test I find that JMeter keep loading classes javascript_gen_cmd__xxx and it makes the test can't reach the throughput I set.

Class loading from JConsole When I click "Perform GC" button in JVisualVM, the classes are unloaded and the throughput is reached.

So i think it would help if I could indicate when the GC should happen, for example when the total number of loaded class reach certain number.

I tried -XX:MetaspaceSize=120M but it didn't trigger class unload when the metaspace usage reached 120MB.


Solution

  • Something like -XX:MaxMetaspaceFreeRatio=30 -XX:MinMetaspaceFreeRatio=10 should cause it to fill up quickly and thus trigger class-unloading GCs.

    Alternatively -XX:+ExplicitGCInvokesConcurrent -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses and using CMS or G1 and firing System.gc() via a timer might work too.