Get active thread count on JMeter

While integrating swirstatdsample from sourceforge.net to retrieve remote host system stats I bumped into an interesting problem which is that rstatd sampler will run forever until we shut it down. So, this make it unsuitable for continuous builders like Hudson that run Performance Plugin to obtain JMeter performance trends. To work around this, I needed to stop the test when JMeter active thread count is equal to 1, i.e. only the rstat monitor should be running. After searching for almost a day I found this from JMeter user manual seccion 19.5.7 “__javaScript”:

Rhinoscript allows access to static methods via its Packages object. See the Scripting Java documentation. For example one can access the JMeterContextService static methods thus: Packages.org.apache.jmeter.threads.JMeterContextService.getTotalThreads()

Thus in JMeter the total threads active at any given time is available at JMeterContextService. You can either use the __javaScript function as explained above or use BeanShell Sampler which allows a more Jav-like syntax:

activeThreadCount = org.apache.jmeter.threads.JMeterContextService.getTotalThreads();

Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.