• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class Factory

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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).]
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic