Discussions

EJB design: creating an EJB singleton

  1. creating an EJB singleton (8 messages)

    I need to create a dispatch table (in memory) that can be accessed by all my ejbs. I do not want to have a copy of this table in all my ejbs, but rather have it reside in memroy somewhere on the server for all ejbs to access.

    I thought of an entity ejb with empty load/store methods, such that the entity represented only the in memory table.

    Any ideas?

    Threaded Messages (8)

  2. creating an EJB singleton[ Go to top ]

    Rob-
    Sounds ok. Make sure that you mark the bean as read-only, transaction-not-supported in the deployment descriptor and set a very long rad-timeout. Also set the max pool size to 1 - this shold increase the likelyhood that the LRU count for the singleton stays high enough for the bean not to get passivated.
  3. creating an EJB singleton[ Go to top ]

    Why don't you try a state full session bean with one set and one get method.

    saket
  4. creating an EJB singleton[ Go to top ]

    I've been thinking about this as well.
    But I wonder how would the other ejbs share the same stateful session bean?
    The reference to the stateful been could be published in a known place ( say JNDI ).
    So, each ejb could gets a reference to the single stateful session bean - they want to share the same state.

    But what happens if two or more of the ejbs access the same stateful session bean concurrently.
    I think that an exception is thrown.(EJB 1.1 spec. section 6.11.6)
  5. creating an EJB singleton[ Go to top ]

    There is no real legal portable way to accomplish this in EJB 1.1

    1) There are no singletons
    2) Singleton design patterns are illegal
    3) Things like maxpoolsize are non portabloe and proprietary
    4) Non read-only static members are illegal
    5) Thread syncrhonization primitives are illegal

    Your best best would be to store the in-memory table into an in-memory database via JDBC. THis would be totally legal and portable and safe.

    Dave Wolf
    Internet Applications Division
    Sybase
  6. creating an EJB singleton[ Go to top ]

    forget abt using EJBs to store the dispatch table info.
    u could simply use a singleton to achieve this. All your EJBs could then access this info as and when they need it.

    i've some similar requirement & i used the above technique. The performance is superb.

    alex

  7. creating an EJB singleton[ Go to top ]

    Please understand the use of singletons is VERY VERY non portable and basically illegal.

    Dave Wolf
    Internet Applications Division
    Sybase
  8. creating an EJB singleton[ Go to top ]

    I just want to create a plain vanilla singleton. My problem is that I want to refresh the values which works fine. The only problem is that we have a number of weblogic instances and I want a simple means of hitting all of them with the changes. Is it possible to share a singleton across instances or is there an alternative solution
  9. how to create singleton EJB[ Go to top ]

    How did you create a singleton stateless EJB? I am using WAS 6.1.