> What is the best pratice when in comes to using cflock looking at the code
> snippets below? Basically does a session-based <cfif> block need to be
> nested within a cflock or not? I'm pretty sure it does. Thanks, Che
>
> <cflock timeout="20" throwontimeout="No" type="READONLY" scope="SESSION">
>   <cfif arrayLen(session.customer.custerrors)>
>        some code here...
>   </cfif>
> </cflock>
>
> or...
>
> <cfif arrayLen(session.customer.custerrors)>
>   <cflock timeout="20" throwontimeout="No" type="READONLY" scope="SESSION">
>        some code here...
>   </cflock>
> </cfif>

Actually, neither of those approaches a best practice standard in CF 6+.

First, you don't need to lock variables unless a race condition may
occur. So the real question is, what other code might be running in
the same session to write to those variables while they're being read?

Second, you don't need to lock variables unless you're concerned about
the outcome of the race condition. For example, when you reinitialize
your application scope, you typically use the same values that were
there before, so it doesn't matter that one request is writing to them
while another is reading from them.

Third, you DON'T WANT TO LOCK AN ENTIRE SCOPE! This is why God* gave
us named locks. In CF 5 and earlier, you had to lock the scope to
prevent serious problems unrelated to the actual race condition. But
in 6+, you can create lock names and lock only the things that need to
be locked. Locking the entire session or application scopes is asking
for performance trouble under load. It simply won't scale.

* or the CF development team, rather.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:326154
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to