Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Date Date
Qty:
Subtotal
Promotions
Estimated Shipping
VAT
Calculated at checkout
Total
Checkout
ColdFusion Help / 

ColdFusion MX: Best practices for locking shared scope variables

Adobe Community Help


Products Affected

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

Macromedia ColdFusion MX offers several enhancements in the way shared scope variables are managed internally in memory. This TechNote details updated best practices for locking shared scope variables.

Best practices for locking shared scope variables remain fundamentally unchanged from previous recommendations, however, there are subtle differences in best practices for locking in ColdFusion MX, due to enhancements in the underlying architecture. In previous versions of ColdFusion, if you did not lock shared scope variables, it caused corrupt blocks of application memory, resulting in server instability or crashes. This is no longer the case with ColdFusion MX and higher. The Java data structures that are used to store shared scope variables are designed to be thread safe. With ColdFusion MX, if you do not lock shared scope variables, it will no longer cause server instability or crashes. Please note, however, there are other potential pitfalls that you may encounter if you do not lock your shared scope variables, as documented below.

The cflock tag has not changed in ColdFusion MX, and the recommendation to use this tag to lock shared scope variables remains the same. Although it is no longer necessary to worry about your server crashing, it is still important to avoidrace conditions in your application code.Race condition is a term that is not specific to ColdFusion programming, but refers to a common issue that needs to be taken into consideration when programming in any multithreaded environment. Simply put, a race condition occurs anytime two threads (in this case, page requests) try to write to the same data at the same time. The following is an example:

<cfset session.cartTotal = session.cartTotal + currentPrice>

If two requests to the page that includes this code are made at the same time, it is possible that in the time between the right-hand side read of the session.cartTotal, and the left-hand-side write for the second page request to execute and modify session.cartTotal. The result is corrupt data. Developers should always ensure that they mitigate or prevent corrupt data when writing application code. Using the cflock tag in this case will prevent the race condition:

<cflock type="exclusive"  timeout="5"><cfset session.cartTotal = session.cartTotal +      currentPrice></cflock>

This example uses cflock with the scope attribute as previously specified in the Best Practices document. It is now acceptable to use the cflock tag with thename attribute instead:

<cflock type="exclusive" name="cartTotal" timeout="5"><cfset session.cartTotal = session.cartTotal +      currentPrice></cflock>

Both examples are equally effective in preventing the race condition. When using the cflock tag with thename attribute, it is important to ensure that you always use the same value when reading and writing to the same shared scope variable. It is often simpler to continue using thescope attribute to avoid making mistakes in your naming, which could result in a race condition. Using thename attribute is useful when you want a high level of granularity in your locking.

Note that you should never ever use different names for locks on code that accesses the same data. For more information, read the documentation chapters, "Using Persistent Data and Locking" and ""Locking code with cflock" in Developing ColdFusion MX Applications with CFML," both part of the ColdFusion MX documentation.

To the top

Additional Information

  • ColdFusion Locking Best Practices
  • ColdFusion MX LiveDocs (Online ColdFusion MX documentation)
Keywords: tn_18235

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement