How To: Force Garbage Collection using WLST on WebLogic Server
How To: Force Garbage Collection using WLST on WebLogic Server


Many times JVM misbehaves, and we may have to force GC. The best way to do it is using WLST.

Although the script doesn’t guarantee that GC would run, but many cases a force GC runs and a lot of memory gets freed up.

I expect you to have:

  1. A Weblogic Server Domain
  2. Name of the server for which you want to perform GC
  3. User name and password for the server

The Script:

  1. Open a text editor and Copy – paste the text given below into the editor.
  2. Save the file as ‘forceGC.py’
  3. Open a new command window à Run ‘setDomainEnv.cmd/.sh’ localted in the ‘domain\bin’ directory
  4. Run the python script using WLST.
  5. java weblogic.WLST forceGC.py
  6. This should have freed up some memory on your server.
  7. The above script runs ‘GC’ on ‘AdminServer’ to run the script of managered server replace the ‘AdminServer’ from the script with the name of the ‘ManagedServer’.
# WLST script which calls GC.
from java.util import *
from javax.management import *
import javax.management.Attribute
print 'starting the script .... '
# please replace userid and password with your AdminServer userid and password
# plz change the IP adresss and port number accordingly
connect('userid','password',url='t3://localhost:port')
state('AdminServer')
# For Force GC ....
domainRuntime()
cd('/ServerRuntimes/AdminServer/JVMRuntime/AdminServer')
print ' Performing Force GC...'
cmo.runGC()
disconnect()
print 'End of script ...'
exit()

Cheers :)

Unni

comments here

February 7, 2009
220 words


Categories
Tags
example hugo blog

Connect. Socialize.

Sponsors