Discussions

EJB design: J2EE Singleton

  1. J2EE Singleton (6 messages)

    Ed Roman introduced the concept of a J2EE singleton via UnicastRemoteObject and registering with RMI and using JNDI to look this up.

    Is there any way of extending this to add resiliance? In weblogic specifics clustering would provide this, however is there a pattern for providing this in a vendor independent way?

    Threaded Messages (6)

  2. J2EE Singleton[ Go to top ]

    John,

     I moved this thread out of the design patterns section, since you aren't posting a "design pattern", but a question.

    take care,

    Floyd
  3. J2EE Singleton[ Go to top ]

    Im not sure I see where this is any different then having a cluster and the singleton only living on one server in that cluster? The lookup would still find it on the one machine and if an entity bean this would roughly equate to a singleton. Whats the point here?

    Where was Ed's pattern posted?

    Dave Wolf
    Internet Applications Division
    Sybase
  4. J2EE Singleton[ Go to top ]

    Hrm, I second that - where is the pattern posted? I always thought that using RMI to implement singleton-like functionality is a standard thing to do.
  5. J2EE Singleton[ Go to top ]

    http://jsp.java.sun.com/javaone/javaone2000/pdfs/TS-678.pdf

    No Statics in EJB
     - Need to still have singleton, but networked singleton instead
    Solution
     - Bind RMI rmeote object to JNDI tree via RMI registry JNDI SPI
     - Clients look up singleton via JNDI


    public class uniqueGen extendsUnicastRemoteObject
       implements Remote {

       private static long uniqueID = System.currentTimeMillis();

       public static synchronized long getUnique() {
       throws RemoteException (
            return uniqueID++;
       }

    Yes we have a singleton but if the instance of weblogic goes down then we loose it unless we use the clustering features. My question is not how to have a singleton but how to make it resiliant.

    John
  6. J2EE Singleton[ Go to top ]

    This question is kind of off topic but applies to your singleton code. Does this code not violate spec. because your are calling a synchronized method from your ejb ?????
  7. J2EE Singleton[ Go to top ]

    I think the distinction needs to be made as to if your are doing this in the App Server JVM or another JVM. If its another I can see the difference with having to wait for a database lock to become free.

    John