Leonti
Leonti

Reputation: 10950

ColdFusion singleton object pool

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?

Upvotes: 3

Views: 502

Answers (1)

baynezy
baynezy

Reputation: 7036

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:-

  1. Use cflock to grant an exclusive lock
  2. Get queueing connecting to your database because of locking / transactions
  3. You have too many things running and you use all the available concurrent threads available to ColdFusion

So the way you are going about it is fine.

Hope that helps.

Upvotes: 6

Related Questions