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: active threads, beanshell, hudson, jmeter, rstat, rstatd, threads