EJB design: How can I control the quantities of different beans in my App?

  1. Too many entity beans and session beans is a threat against my J2EE App's performance. Can singleton and factory pattern work?
  2. Hello Guotong,
    The Best solution to this will be using Flyweight Pattern!!!! You can also use other Patterns like "Service Locator", "Factory Pattern" etc.
  3. I think factory is ok.Flyweight is too complex to me,for there is no many reusable beans in my app.Service Locator?I have not heard it before.How can I find it?
  4. Here is a link to Alur's patterns:

    I'd recommend you to pay attention to SessionFacade.

    It seems to me FleighWeight is implemented by the framework itself, I mean EJB container manages lifecircle of beans.

    Anyway any architecture has its limitation and one moment capacity of your server is over. To many beans even extrimly optimized is a disaster for a server. To not to come to this limit you may 1. try clustering and 2. confine number of instances of beans in the container in its settings.
  5. singleton and factory method[ Go to top ]

    "As far as my knowldger is there,number of beans in an application is reduced only through optimization in code.Here optimizations means reducing the beans by reducing the methods.Here methods can be reduced by removing methods which are related or resulting in same output.As far singleton concerned it helps in reducing instance creation. The Singleton pattern [ GHJV95 ] ensures that only a single instance of a class exists in an application. The meaning of the term "singleton" is not always clear in a distributed environment; in ServiceLocator it means that only one instance of the class exists per class loader.

    The Singleton pattern improves performance because it eliminates unnecessary construction of ServiceLocator objects, JNDI InitialContext objects, and enables caching
    The Web-tier service locator also improves performance by caching the objects it finds. The cache lookup ensures that a JNDI lookup only occurs once for each name. Subsequent lookups come from the cache, which is typically much faster than a JNDI lookup. And in realtion to Factory pattern This pattern helps to model an interface for creating an object which at creation time can let its subclasses decide which class to instantiate. We call this a Factory Pattern since it is responsible for "Manufacturing" an Object. It helps instantiate the appropriate Subclass by creating the right Object from a group of related classes. So It also helps upto some extent"