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
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?
> My question is, since this is a session variable...
should it be locked before
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
a value in your object if you are concerned about race
Which for session variables are relatively rare.
If you where dealing with an object stored in the Application
scope then there would be a much greater chance for race
occur. Thus you would generally be more concerned about
modifying code for these types of objects.
In early versions of ColdFusion there where memory leak
these persisted scopes and the work around was to always lock
thing. This issue has long been resolved, but the old cannon
all the time still persists.
But there can be serious performance, scalability and
to over locking your application. So the better pratice is to
when there is a reason to lock.