---
title: "BeanShell Listener"
description: "Configure the JMeter BeanShell Listener listeners: properties, defaults, and practical usage notes for building reliable load tests."
url: https://docs.jmeter.ai/components/beanshell-listener/
lastUpdated: 2026-10-01
source: docs.jmeter.ai
---

# BeanShell Listener

*Part of the **Listeners** category. Also documented in context in the [full Component Reference](/user-manual/component-reference/#beanshell-listener).*

![BeanShell Listener](/images/screenshots/beanshell_listener.png)

The BeanShell Listener allows the use of BeanShell for processing samples for saving etc.

**For full details on using BeanShell, please see the [BeanShell website.](http://www.beanshell.org/)**

> **Note**
> Migration to [JSR223 Listener](/components/jsr223-listener/)+Groovy is highly recommended for performance, support of new Java features and limited maintenance of the BeanShell library.

The test element supports the `ThreadListener` and `TestListener` methods.
These should be defined in the initialisation file.
See the file `BeanShellListeners.bshrc` for example definitions.

| Name | Required | Description |
| --- | --- | --- |
| Name | No | Descriptive name for this element that is shown in the tree.     The name is stored in the script variable Label |
| Reset bsh.Interpreter before each call | Yes | If this option is selected, then the interpreter will be recreated for each sample.     This may be necessary for some long running scripts.     For further information, see [Best Practices - BeanShell scripting](/user-manual/best-practices/#bsh_scripting). |
| Parameters | No | Parameters to pass to the BeanShell script.     The parameters are stored in the following variables:      **`Parameters`** : string containing the parameters as a single variable **`bsh.args`** : String array containing parameters, split on white-space |
| Script file | No | A file containing the BeanShell script to run.     The file name is stored in the script variable `FileName` |
| Script | Yes (unless script file is provided) | The BeanShell script to run. The return value is ignored. |

Before invoking the script, some variables are set up in the BeanShell interpreter:

- `log` - ([Logger](https://www.slf4j.org/api/org/slf4j/Logger.html)) - can be used to write to the log file
- `ctx` - ([JMeterContext](https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html)) - gives access to the context
- `vars` - ([JMeterVariables](https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterVariables.html)) - gives read/write access to variables:  `vars.get(key); vars.put(key,val); vars.putObject("OBJ1",new Object());`
- `props` - (JMeterProperties - class [`java.util.Properties`](https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html)) - e.g. `props.get("START.HMS");` `props.put("PROP1","1234");`
- `sampleResult`, `prev` - ([SampleResult](https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html)) - gives access to the previous [SampleResult](https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html)
- `sampleEvent` ([SampleEvent](https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleEvent.html)) gives access to the current sample event

For details of all the methods available on each of the above variables, please check the Javadoc

If the property `beanshell.listener.init` is defined, this is used to load an initialisation file, which can be used to define methods etc. for use in the BeanShell script.

## Related

- [Grafana / InfluxDB / Backend Listener](/topics/grafana-influx-backend-listener/)
- [Coordinated Omission Calculator](/tools/coordinated-omission/)
- [Full Component Reference](/user-manual/component-reference/)
- [Functions and Variables](/user-manual/functions/)
