thread-saftey of application-instantiated components
If I create a component (potentially long-running) and instantiate it into the application scope (so all pages can access it), how thread-safe will it be? That is, if two pages call it simultaneously is there any chance one will get the results of the other? Or maybe I'm being paranoid and don't understand what thread-safe really means or where it's a concern? TIA, Oblio This email message may contain privileged and/or confidential information. If you are not the intended recipient(s), you are hereby notified that any dissemination, distribution, or copying of this email message is strictly prohibited. If you have received this message in error, please immediately notify the sender and delete this email message from your computer. ~| Upgrade to Adobe ColdFusion MX7 Experience Flex 2 MX7 integration create powerful cross-platform RIAs http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:268306 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: thread-saftey of application-instantiated components
Yes, the separate calls could get inconsistent data. This is what the CFLOCK tag is for. On 2/1/07, Leitch, Oblio [EMAIL PROTECTED] wrote: If I create a component (potentially long-running) and instantiate it into the application scope (so all pages can access it), how thread-safe will it be? That is, if two pages call it simultaneously is there any chance one will get the results of the other? Or maybe I'm being paranoid and don't understand what thread-safe really means or where it's a concern? -- CFAJAX docs and other useful articles: http://www.bifrost.com.au/blog/ ~| Upgrade to Adobe ColdFusion MX7 Experience Flex 2 MX7 integration create powerful cross-platform RIAs http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:268310 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: thread-saftey of application-instantiated components
There is the possibility for race conditions, so it depends what your component is doing. If your component has the following method: cffunction name=performMath cfargument name=num1 type=numeric required=true / cfargument name=num2 type=numeric required=true / cfset var result = (num1 * 2) + num2 / cfreturn result / /cffunction This method in an application scoped component is thread safe. There is no instance data that could change for each request. But this method is not thread safe: cffunction name=performMath cfset var result = (variables.num1 * 2) + variables.num2/ cfreturn result / /cffunction Thread safety becomes an issue when you are dealing with instance data within the component (the variables scope) that could change based on the actions of a different request. In cases like this you would need to lock the transaction just as you would any other shared scope variable. HTH, Rich Kroll ~| Upgrade to Adobe ColdFusion MX7 Experience Flex 2 MX7 integration create powerful cross-platform RIAs http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:268313 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: thread-saftey of application-instantiated components
Yes, the separate calls could get inconsistent data. This is what the CFLOCK tag is for. This is true only if the method is calling / using instance data. Rich Kroll ~| Upgrade to Adobe ColdFusion MX7 Experience Flex 2 MX7 integration create powerful cross-platform RIAs http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:268314 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: thread-saftey of application-instantiated components
Typically you would have something like this in your cfcs: cffunction name=action returntype=Any cfset var local = StructNew() [actual implementation] cfreturn local.retval /cffunction Using cfset var creates separate scope for each time you invoke your method. If you really need to single thread your calls cflock is good way to do it, but that will limit application scalability. Tero Pikala -Original Message- From: James Holmes [mailto:[EMAIL PROTECTED] Sent: 01 February 2007 13:22 To: CF-Talk Subject: Re: thread-saftey of application-instantiated components Yes, the separate calls could get inconsistent data. This is what the CFLOCK tag is for. On 2/1/07, Leitch, Oblio [EMAIL PROTECTED] wrote: If I create a component (potentially long-running) and instantiate it into the application scope (so all pages can access it), how thread-safe will it be? That is, if two pages call it simultaneously is there any chance one will get the results of the other? Or maybe I'm being paranoid and don't understand what thread-safe really means or where it's a concern? -- CFAJAX docs and other useful articles: http://www.bifrost.com.au/blog/ ~| Upgrade to Adobe ColdFusion MX7 Experience Flex 2 MX7 integration create powerful cross-platform RIAs http:http://ad.doubleclick.net/clk;56760587;14748456;a?http://www.adobe.com/products/coldfusion/flex2/?sdid=LVNU Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:268322 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4