Skip to main content
Known Participant
May 1, 2008
Question

Advise on locking application variables in CF8

  • May 1, 2008
  • 2 replies
  • 252 views
We use application scope variables solely as "constants". We set their values in the application.cfc OnApplicationStart. Their values are then only ever read, never written to.

1. I put cflock statements around them in application.cfc. Is this really necessary?

2. Do I still need to put cflock statements with type="READONLY" when they're referenced in templates? Again, need to emphasize, their values are *never* rewritten. They are only ever read. This is by design, and is a standard we use, so there will never be a future situation where an application scope variable is written to outside of OnApplicationStart.

Thank you.
This topic has been closed for replies.

2 replies

Inspiring
May 1, 2008
larry_schwartz wrote:
> Just found a reference in the CF8 manual stating locks aren't necessary when
> setting application scope variables in OnApplicationStart
>

Yes, one generally does not need to lock access to shared scope
variables, such as application, unless there is a risk of race
conditions that could cause a problem. In other words, if there is no
risk of a race condition, or even if there is a race condition it does
not cause a problem, i.e. 90% of the time, then there is no need to lock.

Over locking code unnecessary can have performance and throughput
consequences to an applications scalability.

This advice is generally left over from ColdFusion 4.5 days, when there
was a bug in CF that could cause memory leak problems if shared scope
variables where not religiously locked. This problem has been resolved
for years, but the advice persists.
Known Participant
May 1, 2008
Just found a reference in the CF8 manual stating locks aren't necessary when setting application scope variables in OnApplicationStart

In the LiveDoc: ColdFusion Developer's Guide / Designing and Optimizing a ColdFusion Application / Defining the application and its event handlers in Application.cfc

It's a frame setup, but the specific page (on my local machine) is htmldocs/help.html?content=appFramework_10.html