<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Locking in CFMX</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Acker</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-51681</link>
		<dc:creator>Acker</dc:creator>
		<pubDate>Thu, 13 Dec 2007 18:32:51 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-51681</guid>
		<description>B,
I thought and suggested that same idea. Mine was more like: Lets keep the CFC in the application scope for loading speed, but INIT() it to the request scope at each request. Basically saying the same thing your saying, but your method is more logical (although your suggesting to use a shared variable within a cfc, which is advised against, but doable).

Cool Cool BarneyB, best single threaded blog about cross threading in shared scopes I&#039;ve ever seen.
-Acker</description>
		<content:encoded><![CDATA[<p>B,<br />
I thought and suggested that same idea. Mine was more like: Lets keep the CFC in the application scope for loading speed, but INIT() it to the request scope at each request. Basically saying the same thing your saying, but your method is more logical (although your suggesting to use a shared variable within a cfc, which is advised against, but doable).</p>
<p>Cool Cool BarneyB, best single threaded blog about cross threading in shared scopes I've ever seen.<br />
-Acker</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-51678</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Thu, 13 Dec 2007 18:21:35 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-51678</guid>
		<description>Acker,

Application-per-project would definitely work, and is probably the least invasive solution.  Another potential would be to use the request-scope CFC as a facade for an application-scope CFC.  So your change the CFC to accept dsn/dbo parameters and put it in the application scope, but you retain the request-scoped CFC which simply delegates to the application-scope CFC.  So assuming the implementation I gave above was how the application-scope CFC was implemented, the request-scope CFC (which you&#039;re already using, and which wouldn&#039;t have it&#039;s API change), would look like this:

[cffunction name=&quot;getSomething&quot;]
[cfreturn application.getSomething(request.dsn, request.dbo) /&gt;
[/cffunction]

You&#039;d have a single instance of the facade CFC that gets copied into the request scope for each request, and a single instance of the &quot;real&quot; CFC that stays in the application scope.  Then all you need to do is ensure request.dsn and request.dbo are defined and you&#039;re done.</description>
		<content:encoded><![CDATA[<p>Acker,</p>
<p>Application-per-project would definitely work, and is probably the least invasive solution.  Another potential would be to use the request-scope CFC as a facade for an application-scope CFC.  So your change the CFC to accept dsn/dbo parameters and put it in the application scope, but you retain the request-scoped CFC which simply delegates to the application-scope CFC.  So assuming the implementation I gave above was how the application-scope CFC was implemented, the request-scope CFC (which you're already using, and which wouldn't have it's API change), would look like this:</p>
<p>[cffunction name="getSomething"]<br />
[cfreturn application.getSomething(request.dsn, request.dbo) /><br />
[/cffunction]</p>
<p>You'd have a single instance of the facade CFC that gets copied into the request scope for each request, and a single instance of the "real" CFC that stays in the application scope.  Then all you need to do is ensure request.dsn and request.dbo are defined and you're done.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Acker</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-51677</link>
		<dc:creator>Acker</dc:creator>
		<pubDate>Thu, 13 Dec 2007 18:16:38 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-51677</guid>
		<description>I gotcha ... Yeah we would have to find/replace all calls to the CFC methods to always supply dsn/dbo ... for now the CFC lies in the request scope, and is re-initiated with every request =(

I say my company needs to make an application name per project.
-Acker</description>
		<content:encoded><![CDATA[<p>I gotcha &#8230; Yeah we would have to find/replace all calls to the CFC methods to always supply dsn/dbo &#8230; for now the CFC lies in the request scope, and is re-initiated with every request =(</p>
<p>I say my company needs to make an application name per project.<br />
-Acker</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-51674</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Thu, 13 Dec 2007 18:11:48 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-51674</guid>
		<description>Acker,

Here&#039;s an example:

[cffunction name=&quot;getSomething&quot;]
  [cfargument name=&quot;dsn&quot; /]
  [cfargument name=&quot;dbo&quot; /]
  [cfquery datasource=&quot;#dsn#&quot;]
    select *
    from #dbo#.mytable
  [/cfquery]
[/cffunction]

Since the dsn and dbo are passed into each individual method invocation, you alleviate the threading issues.  Method arguments and function-local variables (declared with &#039;var&#039;) are always single-threaded, because a method invocation is single threaded.  It&#039;s only the instance state of a shared scope CFC that is shared.

cheers,
barneyb</description>
		<content:encoded><![CDATA[<p>Acker,</p>
<p>Here's an example:</p>
<p>[cffunction name="getSomething"]<br />
  [cfargument name="dsn" /]<br />
  [cfargument name="dbo" /]<br />
  [cfquery datasource="#dsn#"]<br />
    select *<br />
    from #dbo#.mytable<br />
  [/cfquery]<br />
[/cffunction]</p>
<p>Since the dsn and dbo are passed into each individual method invocation, you alleviate the threading issues.  Method arguments and function-local variables (declared with 'var') are always single-threaded, because a method invocation is single threaded.  It's only the instance state of a shared scope CFC that is shared.</p>
<p>cheers,<br />
barneyb</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Acker</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-51658</link>
		<dc:creator>Acker</dc:creator>
		<pubDate>Thu, 13 Dec 2007 15:53:32 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-51658</guid>
		<description>BarneyB, your correct. At my job they are trying to keep the CFC in the application scope, but then they mail-blasted that they needed to move the CFC into the request scope to make it thread safe.

I was so focused on the thread safe part, that I didn&#039;t consider the simplistic fact that it&#039;s in a shared scope.

To fix the problem I came up with the idea of separate application names, per dsn name.

B, could you please elaborate what you meant by &quot;but if you just made the dsn/dbo arguments that are passed into the CFC, the problem should go away&quot; ... I think somethings missing in your statement.</description>
		<content:encoded><![CDATA[<p>BarneyB, your correct. At my job they are trying to keep the CFC in the application scope, but then they mail-blasted that they needed to move the CFC into the request scope to make it thread safe.</p>
<p>I was so focused on the thread safe part, that I didn't consider the simplistic fact that it's in a shared scope.</p>
<p>To fix the problem I came up with the idea of separate application names, per dsn name.</p>
<p>B, could you please elaborate what you meant by "but if you just made the dsn/dbo arguments that are passed into the CFC, the problem should go away" &#8230; I think somethings missing in your statement.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-51562</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Wed, 12 Dec 2007 22:24:56 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-51562</guid>
		<description>Acker,

If you have a CFC in application scope, then it&#039;s instance variables are in application scope as well.  So it&#039;s no different than storing what is in the instance variables directly in the application scope.  If you have per-request data, that needs to be passed into methods of application-scope CFC, rather than being part of the CFC&#039;s internal state.  I don&#039;t know about your specific case, but if you just made the dsn/dbo arguments that are passed into the CFC, the problem should go away.</description>
		<content:encoded><![CDATA[<p>Acker,</p>
<p>If you have a CFC in application scope, then it's instance variables are in application scope as well.  So it's no different than storing what is in the instance variables directly in the application scope.  If you have per-request data, that needs to be passed into methods of application-scope CFC, rather than being part of the CFC's internal state.  I don't know about your specific case, but if you just made the dsn/dbo arguments that are passed into the CFC, the problem should go away.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Acker</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-51510</link>
		<dc:creator>Acker</dc:creator>
		<pubDate>Wed, 12 Dec 2007 14:15:44 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-51510</guid>
		<description>The first example of course is ehh, but it does demo two processes that take time to execute, and could potential be cross threaded. The 3rd example is where it&#039;s at for me.

I think I&#039;ve come to find you can&#039;t store a cfc in the application scope if it needs to be thread safe. I did find I could store a cfc that has not been init(), and then init it to the request scope. All you would gain here is that the cfc is loaded and waiting for use in a non-shared scope.

I&#039;m having the issue that this particular cfc at work requires a dsn, dbo, and was stored in the application scope. Problem was that if another request with a different dsn/dbo came threw, and the application name was the same, they&#039;d cross thread.

All in all I wanted to post somewhere that I don&#039;t think you can safely store a cfc that counts on it&#039;s variables remaining the same for a full request.

TIP!!!! ColdFusion 8 has cfThread with attribute action=&quot;sleep&quot;, this made it very easy for me to loop from=&quot;1&quot; to=&quot;100&quot; and sleep for 200milsecs on every loop. So it made it much much much easier for me to run other machines/browsers to attempt a cross thread.

Damn Descent post BarneyB. I&#039;ve got a &quot;Cynthia&quot; type at my job too, mine is an impatient woman who wouldn&#039;t finish reading an article either, and quick to bash an article with comments such as &quot;keep my hands from shaking&quot;.</description>
		<content:encoded><![CDATA[<p>The first example of course is ehh, but it does demo two processes that take time to execute, and could potential be cross threaded. The 3rd example is where it's at for me.</p>
<p>I think I've come to find you can't store a cfc in the application scope if it needs to be thread safe. I did find I could store a cfc that has not been init(), and then init it to the request scope. All you would gain here is that the cfc is loaded and waiting for use in a non-shared scope.</p>
<p>I'm having the issue that this particular cfc at work requires a dsn, dbo, and was stored in the application scope. Problem was that if another request with a different dsn/dbo came threw, and the application name was the same, they'd cross thread.</p>
<p>All in all I wanted to post somewhere that I don't think you can safely store a cfc that counts on it's variables remaining the same for a full request.</p>
<p>TIP!!!! ColdFusion 8 has cfThread with attribute action="sleep", this made it very easy for me to loop from="1&#8243; to="100&#8243; and sleep for 200milsecs on every loop. So it made it much much much easier for me to run other machines/browsers to attempt a cross thread.</p>
<p>Damn Descent post BarneyB. I've got a "Cynthia" type at my job too, mine is an impatient woman who wouldn't finish reading an article either, and quick to bash an article with comments such as "keep my hands from shaking".</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-36579</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Fri, 14 Sep 2007 21:29:15 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-36579</guid>
		<description>Cynthia,

I would be more than happy to post an alternate walkthough you provide, and/or link to one on your site if that would allay your fears of newbie confusion.</description>
		<content:encoded><![CDATA[<p>Cynthia,</p>
<p>I would be more than happy to post an alternate walkthough you provide, and/or link to one on your site if that would allay your fears of newbie confusion.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cynthia</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-36578</link>
		<dc:creator>Cynthia</dc:creator>
		<pubDate>Fri, 14 Sep 2007 21:20:06 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-36578</guid>
		<description>&gt;Regarding your second point, you&#039;re wrong.  A race condition can ONLY
&gt;exist where there are multiple steps.  

You&#039;re missing the point.  People conceive of writing to an Application or session variable as one &quot;step&quot;.  Their confusion will be reinforced by the first example you used, where clearly there are two steps.  Do query one, then do query two.

I remember having a hard time understanding why I needed to lock  when I was first starting out.  I corresponded with Ben Forta and he cleared everything up, and I can tell you that the way you are explaining things is most definitely going to leave newbies (and probably some others as well, sorry to say) with the wrong ideas.</description>
		<content:encoded><![CDATA[<p>&gt;Regarding your second point, you're wrong.  A race condition can ONLY<br />
&gt;exist where there are multiple steps.  </p>
<p>You're missing the point.  People conceive of writing to an Application or session variable as one "step".  Their confusion will be reinforced by the first example you used, where clearly there are two steps.  Do query one, then do query two.</p>
<p>I remember having a hard time understanding why I needed to lock  when I was first starting out.  I corresponded with Ben Forta and he cleared everything up, and I can tell you that the way you are explaining things is most definitely going to leave newbies (and probably some others as well, sorry to say) with the wrong ideas.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2004/03/10/locking-in-cfmx/comment-page-1/#comment-36560</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Fri, 14 Sep 2007 20:40:06 +0000</pubDate>
		<guid isPermaLink="false">http://barneyb.com/barneyblog/?p=12#comment-36560</guid>
		<description>Cynthia,

I agree (to some extent) with your first statement that the CFQUERY-based example is &quot;odd&quot;.  I do explicitly list both transactions and relative updates as solutions (the latter being preferable) to the problem.  However, the reason for using queries is that the order of events is a lot more clear cut than &lt;cfset application.myVar = application.myVar + 1 /&gt;.  That statement is both a read and a write in a single expression - hardly clear that there are two distinct and fundamentally different operations happening.

Regarding your second point, you&#039;re wrong.  A race condition can ONLY exist where there are multiple steps.  If the &quot;process&quot; is an atomic single action, you CAN&#039;T have a race condition.  You can easily replace &quot;requests&quot; in my statement with &quot;threads&quot; if you prefer that language, but the &quot;multi-step&quot; requirement is still in force.  This is the reason that a relative update on a database is safe to perform without a lock or a transaction: it&#039;s a single atomic operation so a race condition is impossible.</description>
		<content:encoded><![CDATA[<p>Cynthia,</p>
<p>I agree (to some extent) with your first statement that the CFQUERY-based example is "odd".  I do explicitly list both transactions and relative updates as solutions (the latter being preferable) to the problem.  However, the reason for using queries is that the order of events is a lot more clear cut than <cfset application.myVar = application.myVar + 1 />.  That statement is both a read and a write in a single expression &#8211; hardly clear that there are two distinct and fundamentally different operations happening.</p>
<p>Regarding your second point, you're wrong.  A race condition can ONLY exist where there are multiple steps.  If the "process" is an atomic single action, you CAN'T have a race condition.  You can easily replace "requests" in my statement with "threads" if you prefer that language, but the "multi-step" requirement is still in force.  This is the reason that a relative update on a database is safe to perform without a lock or a transaction: it's a single atomic operation so a race condition is impossible.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
