In our ColdFusion application we have stateless model objects. All the data I want I can get with one method call (it calls other internally without saving the state).
Methods usually ask the database for the data. All methods are read only, so I don't have to worry about thread safety (please correct me if I'm wrong).
So there is no need to instantiate objects at all. I could call them statically, but ColdFusion doesn't have static methods - calling the method would mean instantiating the object first.
To improve performance I have created singletons for every Model object. So far it works great - each object is created once and then accessed as needed.
Now my worry is that all requests for data would go through only 1 model object. Should I? I mean if on my object I have a method getOfferData() and it's time-consuming. What if a couple of clients want to access it? Will second one wait for the first request to finish or is it executed in a separate thread? It's the same object after all.
Should I implement some kind of object pool for this?
The singleton pattern you are using won't cause the problem you are describing. If getOfferData() is still running when another call to that function gets called on a different request then this will not cause it to queue unless you do one of the following:-
So the way you are going about it is fine.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With