This content has been marked as final. Show 3 replies
<!--- DO I NEED TO USE CFLOCK HERE???? --->
<!--- AND DO I NEED TO USE CFLOCK HERE???? --->
Even though requests share the instance application.systemOptions, locks are unnecessary. When one request makes the call application.systemOptions.isSiteOnline(), it is independent of another request's call.
> <!--- DO I NEED TO USE CFLOCK HERE???? --->
No, in either situation.
Ask yourself... what would the ramifications be of two requests hitting
that line of code "simultaneously"? The end result is that both of them
are setting the variable to the same static value... so that's what's going
to end up happening: variables.instance.cacheInterval is going to be set to
300 (or 5) in each situation.
You could well with to lock a block of code which - if called
simultaneously via more than one request - could act on shared storage
space (server, application or session data) differently and incorrectly
than is intended.
<!--- application bootstrap process --->
<cfif not structKeyExists(application, isInitialised and not
<!--- initialisation process, whatever it is --->
<cfset application.isInitialised = true>
<cfset application.isInitialised = false>
So a sequence of events could be (say the user is hitting the site with two
REQUEST1: application.isInitialised doesn't exist
REQUEST1: starts the init process
REQUEST2: application.isInitialised STILL doesn't exist
REQUEST2: starts the init process *again*
REQUEST1: sets the application.isInitialised value
REQUEST2: sets the application.isInitialised value
Obviously one does not want two request running the initialisation code.
note this is a slightly contrived example, as if one has an
OnApplicationStart() method, then it will only run once, and that's where
one would have the init code, but it demonstrates the issue.
Google "race condition". Those are the situations in which one needs to
lock blocks of code.
Thank you for your replies. That makes it a lot clear. Much appreciated.