How do I run garbage collector from shell?

If you need to force the execution of Garbage Collection of a Java process from the command line the best option is to use the jcmd utility.

The Java diagnostic command (JCMD) is another JDK tool (available in the bin folder of the JDK) that will trigger a garbage collection routine if the JVM can safely schedule a stop-the-world pause.

Just retrieve the PID of the Java process and execute:

jcmd <pid> GC.run

Other than that, you run the jmap -histo:live <pid> command that will force a full GC on the heap before it prints anything out.


Recommended Articles

Mastering JBoss and WildFly Management with Groovy Shell

Learn how to use the Groovy Shell to manage your JBoss/WildFly application server, bypassing CLI limitations. Discover the benefits of scripting and automate tasks.

Configure JVM Settings in WildFly/JBoss EAP Domain for Optimal Performance

Learn how to configure JVM settings in a WildFly/JBoss EAP domain for optimal performance and scalability. Get expert tips on configuring heap size, max-size, Garbage Collection Algorithms, and more.

Monitor WildFly MBeans and Manage Database Connections via Twiddle - A Comprehensive Guide

Learn how to monitor WildFly MBeans from the shell using Twiddle commands. Discover tips for changing database connection pool sizes and managing connections in JBoss AS 7/WildFly.

Run Struts 2 Application on WildFly with Maven and Archetype - Comprehensive Guide

Learn how to run a Struts 2 application on WildFly using Maven and archetype. Includes Model, View, Controller setup.