Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Class Factory

Posts: 5
  • Mark post as helpful
  • send pies
  • 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,
Posts: 3892
  • Mark post as helpful
  • send pies
  • 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 Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at for other WebSphere information.
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
[This message has been edited by Desai Sandeep (edited November 07, 2001).]
Posts: 14
  • Mark post as helpful
  • send pies
  • 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)
I am going to test your electrical conductivity with this tiny ad:
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic