20 September 2007

Command Line Monitoring of Thread Pool Sizes

Want to periodically view the OC4J thread pool sizes from the command line?

Using Groovy + JMX , its dead simple:
import demo.oc4j.jmx.*;
import java.text.*;

def period = 5000L
def client = new OC4JClient()
def df = DateFormat.getTimeInstance(DateFormat.LONG)

try {
"oc4jadmin", "welcome1")

println "$client\n"

http = client.helper.createGroovyMBean(

system = client.helper.createGroovyMBean(

while(true) {
now = df.format(new Date(System.currentTimeMillis()));
println "$now HTTP:[$http.poolSize] JCA:[$jca.poolSize] System:[$system.poolSize]"
} finally {
println 'Closing'

This makes use of the OC4J helper library, which you can access here.

A simple script to run this would look like this:

set J2EE_HOME=d:\java\oc4j-10133-prod\j2ee\home
set GROOVY_HOME=d:\java\groovy-1.0
set classpath=lib\oc4jgroovy.jar;%GROOVY_HOME%\lib\commons-cli-1.0.jar;/

java -classpath %CLASSPATH% groovy.lang.GroovyShell src\threadlevel.groovy

When the script is run, it produces this sort of output:

Client is connected to: rmi:// oc4jadmin [connectionCaching:
true, httpTunneling:false, locale:not set]

1:03:54 HTTP:[7] JCA:[1] System:[7]
1:03:59 HTTP:[7] JCA:[1] System:[7]
1:04:06 HTTP:[7] JCA:[1] System:[7]
1:04:11 HTTP:[7] JCA:[1] System:[7]

Listening to: Ned's Atomic Dustbin - What Gives My Son?


Anonymous said...

Hello Steve,

where i can found the libary: oc4jgroovy.jar ?

Best Regards,
Ralf (T-Systems)


Buttso said...

Hi Ralf -- I'm sending it to you over email.


Buttso said...

Hi Ralf -- I'm sending it to you via email.


aeh said...

Could I also get a copy? :)

aeh said...

Can I also get a copy? :)

Buttso said...

If you get me your email address and I'd be happy to send it on.


NV - Nimeshkumar Vadgama said...

Hi Buttso,

Interesting article, indeed !!

I would be glad if you could send me oc4jgroovy.jar to my email nimesh.qa@gmail.com

With Regards,