I know there are no race conditions in this case, but it just doesn't feel right not locking in this case as its ONE object I create and let many requests from many applications use it (that's the idea anyway).
Nope -- you only need to lock to prevent race conditions, otherwise you're removing the benefits of CF server's multithreading.
In your case, it looks like you have a stateful CFC that needs to behave like a "request" scope variable since you're storing per-request data as far as I can see.
In other words, your business logic mostly precludes any savings you might get by trying to only instantiate the CFC once - because you need a separate instance for every request anyway I think! However, see below for how I've reworked your code...
I was thinking I need a separate instance or lock it, I choose to lock it, as I feel creating a new instance each time is much more resource hogging, since I want almost every request to use this object. But I could be wrong of course, as I said I am not completely comfortable with this approach.
You have to think about *instances* of objects. Sure the different requests use the same *type* of object, but do they want to share the exact same object?
Create the object (component) instance per request, and if it comes up as a performance bottleneck only then consider optimising.
I was thinking about using init() but just because everyone else is using it did not seem like a good reason enough ;-))
...usually meaning that it's best practice! ;)
Coldfusion doesn't have a language level constructor mechanism so init() is the next best thing.
I guarantee that later on you'll write a component that will need to take params in the constructor and execute some logic based upon that. You'll have some components using init() and some that don't, which is inconsistent and just plain confusing.
Don't forget to <cfreturn this /> in your init() method.
Sorry I can't answer the rest -- have to scoot!
-- tim lucas
http://www.toolmantim.com
--- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/
