Wednesday, March 3, 2010

WLST script to take thread dump after 5 seconds.

In certain scenarios, it possible to get thread dumps without using manual input such as a 'kill -3" or "CTRL+BREAK." is not This document provides a short WLST script that will take thread dumps at regular intervals.

Solution

connect ('weblogic','weblogic','t3://localhost:7001')

for counter in range(10): serverName = 'AdminServer'
counter = 0
sleepTime = 5000

java.lang.Thread.sleep(sleepTime)
fileName = 'dump' + serverName + '_' + (java.util.Calendar.getInstance().getTimeInMillis()).toString() + '.dmp'
threadDump('true', fileName, serverName)

This script will take 10 thread dumps 5000 ms (that is, 5 seconds) apart. Replace serverName, username, password, and URL with your particular details. Change sleepTime (in ms) if you want to change the frequency of the thread dumps. Change the range (currently 10) if you want to have fewer or more thread dumps taken.

Save the code in a file, e.g. "ThreadDumps.py."

Call it from WLST using the following command:
java weblogic.WLST ThreadDumps.py

No comments: