# Can Two CopyStorm Jobs Run on the Same Database at the Same Time?

Having multiple CopyStorm jobs run on the same database at the same time is perfectly OK if the two jobs are processing different Salesforce tables. However, what if two CopyStorm jobs are running at the same time on the same set of tables? How can this happen?

* CopyStorm is scheduled to run every 30 minutes.
* A CopyStorm job starts at 12:00.
* At 12:30 the first CopyStorm job is still running because there were a LOT of updates in Salesforce.
* The scheduler starts a second CopyStorm job at 12:30.

In practice this is unlikely to cause an issue because the second job will not catch up with the first job (e.g. the two jobs will never be operating on the same table at the same time by happenstance). However, this is a condition that is easily AND SHOULD BE avoided.

## How to Avoid a Job Running Twice on Linux and Mac

To prevent the same job running twice (or more times) is the [flock](http://linux.die.net/man/1/flock) command. The following script ensures that the CopyStorm job never runs twice at the same time:

```
(
flock -x 9
sh /home/greg/bin/CopyStorm/CopyStorm.sh -run /home/greg/copyStormConfig/MyJob.copyStorm
) 9>/tmp/MyJob.lock
```

If the script is run twice, the second script will wait (at the flock) command until the first script completes. Once the first invocation of the script completes, the flock command will return and the second invocation will continue.

## How to Avoid a Job Running Twice on Windows

The easiest way to prevent a job from running twice on Windows is to use the Windows scheduler. By default, the Windows Scheduler will not start a scheduled task again if a previous invocation is still running.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.capstorm.com/frequently-asked-questions/how-does-copystorm-work/can-two-copystorm-jobs-run-on-the-same-database-at-the-same-time.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
