On Thu, Jul 10, 2008 at 6:02 PM, Doug Boude (rhymes with 'loud') < [EMAIL PROTECTED]> wrote:
> > At times, writing a CFC that is to be utilized as a singleton can be a bit > tricky for me...trying to visualize it being accessed by multiple users > simultaneously leaves me thinking that maybe there's something I overlooked. > So, it occurred to me to simply wrap my singleton call in a cflock tag, then > there's no doubt at all that my singleton calls won't be stepping on each > other's toes. > So the question is, first of all, how does wrapping an object call in > cflock tags strike you as a developer? Does it seem hacky or otherwise > unsettling? Secondly, can a cfc (generally speaking) act as a singleton if > we do wrap it in an exclusive lock like that? Of course I know that a lot of > the answer depends upon how the CFC is written, but assuming the object > isn't persisting values between calls, would you consider something like > this acceptable, or is it far far from best practice? It's a bad sign. If you have a Singleton that needs to be concerned about whether more than one thread uses it at the same time, then you either don't actually have a Singleton, or you have a Singleton that need to implement its own internal synchronization mechanism. Personally, I've never had to lock anything in a Singleton before. > > Lastly, can anybody offer or point me to some resources that provide good > solid guidelines to follow when writing a CFC that is to be utilized as a > Singleton? > Basically, var-scope all method-local variables, and ensure that any instance data in the Singleton doesn't change state (in other words, instance data is defined at object creation and then is not altered). That's pretty much it! > > Thanks! > Doug B > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;203748912;27390454;j Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308910 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

