Coldfusion scheduled tasks - have multiples running

I have a scheduled task that runs every 3 minutes.  The first thing it does is check for a flag in a database table.  If that flag is true,  it reads a batch of records and checks for duplicates.  The problem is,  I have 3 of that task running.  Each one was started 3 minutes after the other.  Those other 2 task should not be running since the task is already running.  Am I right?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If the task takes more than three minutes to run, then you would have more than one running at the same time.   But I would think that the task would not take that long to run.   How do you know you have three running at once?

If the flag is not set, then the task would just complete without doing anything, true?   So, that would prevent the next task from processing if it happens to start before the previous one finishes.

And of course, the big question is...  what process do you have that is constantly creating duplicate records that you have to clean up?
lantervAuthor Commented:
FusionReactor shows three copies running.

If a user wants to run the "duplicates" process,  they click on a button that updates the database table with the word "started".  That's what causes the scheduled task to "not cfabort" and start reading the individuals table and checking for duplicates.  It only processes some 500 rows at a time.  I use this process to keep from swamping the server. When zero rows are read, I update the database table with "stopped" and the scheduled task will just cfabort.

We have a table of individuals.  We may add rows from a "roster".  We also allow site users to create their own record.  We normally get about 200 possible duplicates from 180,000 users.  We run the process once a month.

If I'm wrong about scheduled tasks not running when the process is still running from a previous launch,  I need to re-think my process.
So, if I understand correctly, the de-duplicating code only runs by the scheduled task and no more often than every three minutes.  The first thing it does is to check the flag, if the flag is "started" then it continues, if it is not set to "started", then it aborts.

The users are able to set the flag to "started", but the user cannot start the de-duplicating process - only the scheduled task does that.

How long does each run of the de-duplicating process take to process 500 rows at once?  Hopefully only a few seconds?
If everything I just said is true, it sounds like it should prevent multiple processes from running at the same time - provided the process is shorter than 3 minutes.     How does your process differ from this?     The important part is that nothing starts the process except the scheduled task...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

lantervAuthor Commented:
This is what FusionReactor is currently showing.  Current time on the server is 17:58.

Started           Status Code /      IP                  ID / Thread                                        Time (ms)
08-Apr-2015   Running   40854 ajp-bio-8012-exec-56            115,372  93

08-Apr-2015   Running   40851 ajp-bio-8012-exec-55             295,696  515

08-Apr-2015   Running   40847 ajp-bio-8012-exec-8               474,998   656
lantervAuthor Commented:
I'm getting cfquery timeout errors in the app log.  Apparently there are other problems I need to work out.
Try running the statement on the page so you can watch it run and see what happens
(no points...)

Also, I'd recommend adding some logging to the process. Dump the start (and end) times and the status from the db so you can verify whether it actually is running multiple times.

As an aside, I remember this blog tip about using cflock to prevent tasks from overlapping. Basic idea is to wrap the entire code block of a scheduled task in an exclusive lock, with a low timeout. So the 1st time it runs, it'll grab an exclusive lock. If you try and run it again, before the first instance finishes, you won't be able to obtain a lock, so it won't run - not until the 1st run finishes.
lantervAuthor Commented:
I don't know what made me think CF would not execute a scheduled task if a previous launch was still running.  Anyway,  the CFlock tip was useful.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.