I have an application with various "worker" objects that are wasting resources for no reason. For example, one "worker" object has on average 51 instances for any given page request. I really only need 1 instance of this "worker" object, but it does have some instance data. The way I would solve this with Java is to use the singleton pattern where I can ensure the only one instance is created and manage that instance data when it is first created.
Implementing the singleton pattern is Java is pretty easy, but requires two things that CFCs don't have; constructors and static modifiers. Looking into how to solve this problem with what CFML does provide I came up with the following solution. First, I created a "manager" CFC to maintain data in the application scope. Second, instead of using CreateObject() to instantiate these "worker" objects, the "manager" CFC is asked for an instance. The "manager" attempts to find an instance in the application scope. If it finds one it simply returns it; else it creates an instance and returns that. The above solve the problem of having more "worker" instances than needed and makes a huge difference in terms of performance. However, now there are a ton of "manager" instances, which isn't bad in terms of performance since they are small and have no instance data. But, I don't need a bunch of "manager" instances either. Somewhere, somehow, something needs to do the work that is in the "manager" CFC now. However, if that thing is a CFC then the problem doesn't seem to be solvable. This is especially true since the application in question is Mach-II based thus requiring the logic in CFCs. I have thought about creating the "manager" object in Java to get around this problem, but that is less than ideal. -Matt ---------------------------------------------------------- You are subscribed to cfcdev. To unsubscribe, send an email to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email. CFCDev is run by CFCZone (www.cfczone.org) and supported by Mindtool, Corporation (www.mindtool.com). An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]
