Skip to main content
Inspiring
February 15, 2019
Answered

cflock usage

  • February 15, 2019
  • 1 reply
  • 489 views

I have a process that reads an ID from a table, increments it by 1 then calls several pages that write the new ID to different tables. I want to use cflock to prevent a second user from reading the ID before it gets incremented and written back out. This process can happen on several different pages. If the lock name is universal across the site does CF prevent it from running on page2.cfm if page1.cfm is running it and it's locked? My code looks like this:

<cflock name = "ConnectBack" timeout = "50" type = "Exclusive">

!- Get current ID

!- Increment it by one

!-  Cflocation pages that write it out to new tables

</cflock>

Thanks....

This topic has been closed for replies.
Correct answer Dave Watts

Yes, named locks are used instance-wide, so if you have two pages with the same lock name - even if they're in different CF applications - one will prevent the other from running simultaneously as the first if either is an exclusive lock. I would recommend you minimize the work done within these locks to what is absolutely required. For example, you could lock the process of getting a new incremental value, but you don't need the CFLOCATION to be locked as well. (You would need the CFLOCATION to fail if you don't successfully get a new incremental value, so you'd have to handle that with CFTRY/CFCATCH, but you'd have to do that anyway.)

Dave Watts, Eidolon LLC

1 reply

Dave WattsCommunity ExpertCorrect answer
Community Expert
February 15, 2019

Yes, named locks are used instance-wide, so if you have two pages with the same lock name - even if they're in different CF applications - one will prevent the other from running simultaneously as the first if either is an exclusive lock. I would recommend you minimize the work done within these locks to what is absolutely required. For example, you could lock the process of getting a new incremental value, but you don't need the CFLOCATION to be locked as well. (You would need the CFLOCATION to fail if you don't successfully get a new incremental value, so you'd have to handle that with CFTRY/CFCATCH, but you'd have to do that anyway.)

Dave Watts, Eidolon LLC

Dave Watts, Eidolon LLC