---
title: "__threadNum"
description: "JMeter __threadNum function reference: syntax, parameters, and practical examples for parameterizing test plans with dynamic values."
url: https://docs.jmeter.ai/functions/threadnum/
lastUpdated: 2026-10-01
source: docs.jmeter.ai
---

# __threadNum

*Also documented in context in the [full Functions and Variables reference](/user-manual/functions/#__threadNum).*

**TL;DR:** `__threadNum` returns the current thread’s number (1, 2, 3, …) within its Thread Group — useful for deriving per-thread test data (e.g. `user${__threadNum}`) without a CSV file.

The thread number function simply returns the number of the thread currently
being executed.  These numbers are only locally unique with respect to their ThreadGroup, meaning thread #1 in one threadgroup
is indistinguishable from thread #1 in another threadgroup, from the point of view of this function.

> **Note**
> The function returns a number between one and the max number of running threads. Note that if you’re using
> JSR223 code with [JMeterContext](https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterContext.html) object (`ctx` variable),
> the below code returns a number between zero and (max number of running threads minus one)
>
> ```plaintext
> ctx.getThreadNum()
> ```

There are no arguments for this function.

Usage Example:

```bash
\${__threadNum}
```

returns a number between 1 and the max number of running threads configured in the containing Thread Group

> **Note**
> This function does not work in any Configuration elements (e.g. User Defined Variables) as these are run from a separate thread.
> Nor does it make sense to use it on the Test Plan.

### Example

```plaintext
${__threadNum}   → e.g. 3 for the third thread started
```

Combine with [__threadGroupName](/functions/threadgroupname/) when a test plan has multiple Thread Groups and per-group-scoped IDs are needed. For genuinely unique values across a distributed run (multiple injectors), prefer [__UUID](/functions/uuid/) — thread numbers restart from 1 on every injector.

## Related

- [Functions and Variables Guide](/topics/functions-and-variables/)
- [Regex Extractor Builder](/tools/regex-tester/)
- [Thread Groups & Workload Modeling](/topics/thread-groups-workload-modeling/)
- [Full Functions Reference](/user-manual/functions/)
- [Component Reference](/user-manual/component-reference/)
