I need to create a CF(class factory). The CF should store references (probably in a Map). When the method is called the CF should check is a reference is available, if yes, it should return the reference to the client else create a new instance, store in the Map (for subsequent requests) and return a reference to the client. Is this a feasible? My concern is what happens when 2 clients get reference to the object at the same time. When both the clients call methods on the object will it cause a problem since both the clients are using the same object reference, Thanks, Tanner
Well, then one option is to have a pool of instances rather than just one. Your clients can then return the instances to the pool when they are finished with them. Kyle ------------------ Kyle Brown, Author of Enterprise Java (tm) Programming with IBM Websphere See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
"Tanner" Your name does not agree with the Javaranch guidelines.Please take a moment and re-register after reviewing the guidelines available here Thank you for your cooperation.We look forward for your contribution in the forum after registering as per Javaranch guidelines. Best Regards, Sandeep [This message has been edited by Desai Sandeep (edited November 07, 2001).]
Perhaps you want only one reference/object, if that's the case you can synchronize the method or block of code returning the reference. If you create a pool or collection of instances, then you have to know when all instances are 'dereferenced' or not required anymore (I guess keep a count of how many instances have been created)