---
schema_version: "1"
id: a2e2b2a95bc76e332f9f4a4528cb4b1b5b0f2b19cd4c411498266c1f0bd33bc7
title: Scheduler (<scheduler/>)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/acb-component-scheduler.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/acb-component-scheduler
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f6401438cbbd00a7c34b327c90eae108b77df86fea0cce124363cde0b3b4772f
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Scheduler (<scheduler/>)

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Trigger execution of a flow based on a time-based condition. For example, a Scheduler might create
and send a message that will trigger the flow processing every 5 seconds or every day at 12:00 in a
given time zone.

The Scheduler sets a scheduling strategy at a fixed frequency or an interval based on a cron
expression.

When adding a Scheduler to your Mule application, consider these points:

- Schedulers use the same timezone as the machine on which Mule is running. However, if an
  application is running in CloudHub, the Scheduler conforms to the UTC timezone, regardless of the
  geographic region in which the application is running.

  To set a different time zone for the Scheduler, see `timeZone` in the
  [cron scheduling strategy attributes](#cron-attributes).

- The `disallowConcurrentExecution` property enables you to prevent the Scheduler from triggering
  the execution of the flow while a previously-triggered execution is running.

- If [back-pressure](https://docs.mulesoft.com/mule-runtime/latest/execution-engine#backpressure) occurs because no
  resources are available at the time of the scheduled trigger, Mule skips that execution.

- In a Mule runtime engine cluster or multi-worker CloudHub deployment, the Scheduler executes only
  on the primary node (that is, only in one Mule instance).

## Component XML

This component supports the following XML structure:

```xml
<scheduler doc:name="Scheduler" doc:id="snswxf" >
  <scheduling-strategy/>
</scheduler>
```

Scheduler (`<scheduler/>`) attributes are configurable through the UI and XML.

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Attribute XML</th><th>Description</th></tr></thead><tbody><tr><td><p><strong>Scheduler</strong> (default)</p></td><td><p><code>doc:name</code></p></td><td><div><div><p>Editable name for the component to display in the canvas.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>doc:id</code></p></td><td><div><div><p>Automatically generated identifier for the component.</p></div></div></td></tr><tr><td><p><strong>Disallow concurrent execution</strong></p></td><td><p><code>disallowConcurrentExecution</code></p></td><td><div><div><p>When this attribute is set to <code>true</code>, the Scheduler skips its scheduled execution if a previous execution is still running. Once the flow finishes, the Scheduler executes at the next configured interval. The default value is <code>false</code>.</p></div></div></td></tr></tbody></table>

**Scheduling strategy** (`<scheduling-strategy/>`) is a child element of Scheduler.

<table><colgroup><col> <col></colgroup><thead><tr><th>Child Element</th><th>Description</th></tr></thead><tbody><tr><td><p><code>&lt;scheduling-strategy/&gt;</code></p></td><td><div><div><p>Accepts a <a href="#fixed-frequency-attributes"><code>&lt;fixed-frequency/&gt;</code></a> or <a href="#cron-attributes"><code>&lt;cron/&gt;</code></a> configuration.</p></div></div></td></tr></tbody></table>

### Fixed Frequency Attributes

Scheduler accepts a fixed frequency (`<fixed-frequency/>`) element that accepts these attributes:

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Attribute XML</th><th>Description</th></tr></thead><tbody><tr><td><p>N/A</p></td><td><p><code>frequency</code></p></td><td><div><div><p>The frequency at which the Scheduler triggers the flow given the <code>timeUnit</code> setting. Defaults to <code>1000</code>.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>startDelay</code></p></td><td><div><div><p>The amount of time to delay execution of the Scheduler for the first time after the application starts. This property uses the same <code>timeUnit</code> as the frequency. Defaults to <code>0</code>.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>timeUnit</code></p></td><td><div><div><p>One of the following time units for the values of <code>frequency</code> and <code>startDelay</code>: <code>MILLISECONDS</code>, <code>SECONDS</code>, <code>MINUTES</code>, <code>HOURS</code>, or <code>DAYS</code>. Defaults to <code>MILLISECONDS</code>.</p></div></div></td></tr></tbody></table>

See the [fixed frequency examples](#example1).

### Cron Attributes

For more complex scheduling, configure a cron expression in the `<cron/>` element.

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Attribute Name</th><th>Attribute XML</th><th>Description</th></tr></thead><tbody><tr><td><p>N/A</p></td><td><p><code>expression</code></p></td><td><div><div><p>A cron expression for triggering the Scheduler. There is no default cron expression. For guidance with expressions, see <a href="#cron-expressions">Cron Expressions</a>. Example: <code>expression="1 1 1 1,7 * ?"</code>.</p></div></div></td></tr><tr><td><p>N/A</p></td><td><p><code>timeZone</code></p></td><td><div><div><p>Time zone passed as a system property, or in a machine’s operating system. <a href="https://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html" target="_blank" rel="noopener">Java time zone</a> values are supported. Avoid Java abbreviations, such as <code>PST</code> and <code>AGT</code>, and instead use the full-name Java equivalents, such as <code>America/Los_Angeles</code>. Example: <code>timeZone="America/Argentina/Buenos_Aires"</code>.</p></div></div></td></tr></tbody></table>

See the [cron examples](#example2).

## Examples

### Fixed Frequency Examples

In the following example, the Scheduler executes every fifteen seconds:

```xml
<flow name="ex-fixed-frequency-flow" >
  <scheduler doc:name="Scheduler">
    <scheduling-strategy>
      <fixed-frequency frequency="15" timeUnit="SECONDS" />
    </scheduling-strategy>
  </scheduler>
  <!-- One or more processors here. -->
</flow>
```

In the following example, the Scheduler skips its execution if the flow takes longer to complete
than the fixed frequency of 10 milliseconds:

```xml
<flow name="scheduler-disallowConcurrentExecution-ex" >
  <scheduler doc:name="Scheduler" disallowConcurrentExecution="true" >
    <scheduling-strategy>
      <fixed-frequency frequency="10" timeUnit="MILLISECONDS"/>
    </scheduling-strategy>
  </scheduler>
  <!-- processors here -->
</flow>
```

Each time a Scheduler skips its execution, Mule logs an `Execution skipped` message, for example
(edited for readability):

```logs
INFO  2022-11-09 15:15:43,082 ...
...scheduler.DefaultSchedulerMessageSource:
Flow 'scheduler-disallowConcurrentExecution-ex' is already running and
'disallowConcurrentExecution' is set to 'true'. Execution skipped.

INFO  2022-11-09 15:15:43,083 ...
...scheduler.DefaultSchedulerMessageSource:
Flow 'scheduler-disallowConcurrentExecution-ex' is already running and
'disallowConcurrentExecution' is set to 'true'. Execution skipped.
```

The following example shows a fixed-frequency scheduling strategy that executes the Scheduler every
10 seconds after an initial 10 second delay:

```xml
<scheduler doc:name="Scheduler" >
  <scheduling-strategy >
    <fixed-frequency frequency="10" timeUnit="SECONDS" startDelay="10"/>
  </scheduling-strategy>
</scheduler>
```

### Cron Examples

The following example uses a cron expression to trigger the generation of a Mule message in a new
execution of the flow every fifteen seconds:

```xml
<flow name="ex-cron-expression-flow" >
  <scheduler doc:name="Scheduler" >
    <scheduling-strategy >
      <cron expression='0/15 * * * * ? '/>
    </scheduling-strategy>
  </scheduler>
  <!-- One or more processors here. -->
</flow>
```

The following example uses a cron expression to trigger the flow at 12:00 every day in the
`America/Los_Angeles` time zone.

```xml
<flow name="componentsFlow">
  <scheduler>
    <scheduling-strategy>
      <cron expression="0 0 12 * * ?" timeZone="America/Los_Angeles"/>
    </scheduling-strategy>
  </scheduler>
  <logger message="my message"/>
</flow>
```

## Cron Expressions

Cron is a widely used standard for describing time and date information. The Cron Expression
(`<cron expression />` scheduling strategy (`<scheduling-strategy >`) is useful for triggering a
flow at intervals not available through the Fixed Frequency scheduling strategy.

The Scheduler keeps track of every second and creates a Mule event when the Quartz Cron expression
matches your time-date setting. You can trigger the event just once or at regular intervals.

A date-time expression consists of six required settings and can include the optional year setting.
Specify the settings in the following order:

1.  Seconds (`0`\-`59`)

2.  Minutes (`0`\-`59`)

3.  Hours (`0`\-`23`)

4.  Day of month (`1`\-`31`)

5.  Month (`1`\-`12` or `JAN`\-`DEC`)

6.  Day of the week (`1`\-`7` or `SUN`\-`SAT`)

7.  Year (empty or a 4-digit year between `1970`\-`2099`, for example, `2019`)

The Scheduler supports Quartz Cron expressions. Here are a few examples:

<table><colgroup><col> <col></colgroup><thead><tr><th>Expression</th><th>Behavior</th></tr></thead><tbody><tr><td><p><code>1/2 * * * * ?</code></p></td><td><p>Run every 2 seconds of the day, every day.</p></td></tr><tr><td><p><code>0 15 10 ? * *</code></p></td><td><p>Run at 10:15 a.m., every day. <code>0 15 10 * * ? *</code> and <code>0 15 10 * * ?</code> produce the same effect.</p></td></tr><tr><td><p><code>0 15 10 * * ? 2019</code></p></td><td><p>Run at 10:15 a.m., every day during the year 2019.</p></td></tr><tr><td><p><code>0 * 14 * * ?</code></p></td><td><p>Run every minute starting at 2pm and ending at 2:59pm, every day.</p></td></tr><tr><td><p><code>0 0/5 14 * * ?</code></p></td><td><p>Run every 5 minutes starting at 2pm and ending at 2:55pm, every day</p></td></tr><tr><td><p><code>1 1 1 1,7 * ?</code></p></td><td><p>Run the first second of the first minute of the first hour, on the first and seventh day, every month.</p></td></tr></tbody></table>

The Scheduler component also supports Quartz Scheduler special characters:

- `*`: All values.

- `?`: No specific value.

- `-`: Range of values, for example, `1-3`.

- `,`: Additional values, for example, `1,7`.

- `/`: Incremental values, for example, `1/7`.

- `L`: Last day of the week or month, or last specific day of the month (such as `6L` for the last
  Saturday of the month).

- `W`: Weekday, which is valid in the month and day-of-the-week fields.

- `#`: "nth" day of the month. For example, `#3` is the third day of the month.

This example logs the message "hello" every second:

```XML
<flow name="cronFlow" >
  <scheduler doc:name="Scheduler" >
    <scheduling-strategy >
      <cron expression="* * * * * ?" />
    </scheduling-strategy>
  </scheduler>
  <logger level="INFO" doc:name="Logger" message='"hello"'/>
</flow>
```

Note that there are many free online tools that can help you build Cron expressions.

## Error Handling

At least one processor must follow the Scheduler. Processors include Mule components and connector
operations, such as an HTTP Request operation or Transform Message component. Failure to provide a
processor produces a `MuleRuntimeException` and causes the deployment of the Mule application to
fail with the following ERROR message in the logs (edited for readability):

```logs
ERROR ...MuleRuntimeException ...
The content of element 'flow' is not complete.
One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor,
"http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor}'
is expected.
```

## See Also

- [Mule Events](https://docs.mulesoft.com/mule-runtime/latest/about-mule-event)

- [Trigger a Scheduler On Demand](https://docs.mulesoft.com/anypoint-code-builder/int-trigger-flows#trigger-scheduler-on-demand)
