• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Locking and Objects

Participant ,
Apr 03, 2008 Apr 03, 2008

Copy link to clipboard

Copied

I have been looking up a lot of information on locking shared-scope variables lately, because I dont really do it at all and I probably should. My question revolves around something else I had posted about a couple of days ago about creating objects in the session scope.

I have user.cfc that holds information such as username. etc... I have methods such as getFirstName(), getLastName(), and setUser(userID). These variables are references as #Session.User.getFirstName()# as expected.

My question is, since this is a session variable... should it be locked before access?
TOPICS
Advanced techniques

Views

267

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 04, 2008 Apr 04, 2008

Copy link to clipboard

Copied

LATEST
jeby wrote:
> My question is, since this is a session variable... should it be locked before
> access?
>

Probably not very often. You should not have to do a lock when you are
just reading values. And you would only need to do a lock when changing
a value in your object if you are concerned about race conditions.
Which for session variables are relatively rare.

If you where dealing with an object stored in the Application or Server
scope then there would be a much greater chance for race conditions to
occur. Thus you would generally be more concerned about locking
modifying code for these types of objects.

In early versions of ColdFusion there where memory leak problems with
these persisted scopes and the work around was to always lock every
thing. This issue has long been resolved, but the old cannon of locking
all the time still persists.

But there can be serious performance, scalability and throughput issues
to over locking your application. So the better pratice is to only lock
when there is a reason to lock.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation