> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/components/system/lock.md).

# Lock

Ensures the integrity of shared data.

## Component Signature

```
<bx:Lock name=[string]
scope=[string]
type=[string]
timeout=[Integer]
throwOnTimeout=[boolean]
cacheName=[string] />
```

### Attributes

| Atrribute        | Type      | Required | Description                                                                                                                                                                                                                                     | Default     |
| ---------------- | --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `name`           | `string`  | `false`  | <p>Lock name. Mutually exclusive with the scope attribute. Only one request can execute the code within a lock component with a given<br>name at a time. Cannot be an empty string.</p>                                                         |             |
| `scope`          | `string`  | `false`  | <p>Lock scope. Mutually exclusive with the name attribut Lock name. Only one request in the specified scope can execute the code<br>within this component (or within any other lock component with the same lock scope scope) at a time.</p>    |             |
| `type`           | `string`  | `false`  | readOnly: lets more than one request read shared data. exclusive: lets one request read or write shared data.                                                                                                                                   | `exclusive` |
| `timeout`        | `Integer` | `false`  | <p>Maximum length of time, in seconds, to wait to obtain a lock. If lock is obtained, tag execution continues. Otherwise, behavior<br>depends on throwOnTimeout attribute value. A value of 0 will wait forever.</p>                            | `0`         |
| `throwOnTimeout` | `boolean` | `false`  | <p>True: if lock is not obtained within the timeout period, a runtime exception is thrown. False: if lock is not obtained,<br>the body of the component is skipped and execution continues without running the statements in the component.</p> | `true`      |
| `cacheName`      | `string`  | `false`  |                                                                                                                                                                                                                                                 |             |

## Examples

### Script Syntax

```java
bx:lock timeout="60" scope="session" type="exclusive" {
	session.MYVAR = "Hello";
}

```

### Tag Syntax

```java
<bx:lock timeout="60" scope="session" type="exclusive"> 
 <bx:set session.MYVAR = "Hello" > 
 </bx:lock>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/components/system/lock.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
