EJB3 and the Singleton

As per the defination of Singleton EJB
A Singleton EJB is a session bean component that is instantiated once per application.
In other words, all requests to the singleton will be routed to the single instance of the Singleton bean instance.
( I know taht a Stateless session bean is not applicable here , as the container might maintain a pool of
these stateless bean instances
But Can you please tell me how this is different from a normal Statefull Session Bean ??

RaviKIran wrote:
As per the defination of Singleton EJB
A Singleton EJB is a session bean component that is instantiated once per application.Where did you find this definition? It contradicts the usual meaning of session bean as per EJB version 1 to 3.
Note that singleton EJB are expected to be a feature included in the next version EJB 3.1. Whether it will be considered a session bean (application session vs user session) is open to debate, and is not strictly necessary.
EDIT: my mistake: Sun does describe singleton EJB as being a new form of session bean. See this [enterprise tip|http://blogs.sun.com/enterprisetechtips/entry/a_sampling_of_ejb_3] .
Edited by: jduprez on Oct 19, 2009 7:57 AM

Similar Messages

  • "requires unreachable" warning emitted when using static variables and the singleton pattern

    I'm implementing code contracts on an existing code base and I've come across this situation in a few places. Wherever we have additional logic with code contracts where a singleton instance is instantiated, all code contracts emit a "reference use
    unreached", or "requires unreachable" warning.
    The code below demonstrates this.
    static string instance = null;
    static string InstanceGetter()
    if (instance == null)
    instance = "initialized";
    AdditionalLogic(instance); // requires unreachable warning on this line
    return instance;
    static void AdditionalLogic(string str)
    Contract.Requires(str != null);
    Console.WriteLine(str);

    Would the class get unloaded even if the Singleton object has some valid/reachable references pointing to it?
    On a different note, will all the objects/instances of a class get destroyed if the class gets unloaded.That's the other way round, really: instances cannot be garbage-collected as long as they are strongly reachable (at least one reference pointing to them), and classes cannot be unloaded as long as such an instance exists.
    To support tschodt's point, see the JVM specifications: http://java.sun.com/docs/books/jvms/second_edition/html/Concepts.doc.html#32202
    *2.17.8 Unloading of Classes and Interfaces*
    A class or interface may be unloaded if and only if its class loader is unreachable. The bootstrap class loader is always reachable; as a result, system classes may never be unloaded.
    Will the same case (Custom ClassLoader getting unloaded) occur if I write the singleton using the code wherein we lazily initialize the Singleton (and actually create a Singleton instance rather than it being a Class/static variable).You should check the meaning of this vocabulary ("object", "instance", "reference"): http://download.oracle.com/javase/tutorial/java/javaOO/summaryclasses.html
    The difference between the lazy vs eager initializations is the time when an instance is created. Once it is created, it will not be garbage collected as long as it is reachable.
    Now I'm wondering, whether being referenced by a static attribute of a class guarantees being reachabe. I'm afraid not (see the JLS definition of reachable: http://java.sun.com/docs/books/jls/third_edition/html/execution.html#44762). That is, again, unless the class has been loaded by the system class loader.

  • How we can limit the number of concurrent calls to a WCF service without use the Singleton pattern or without do the change in BizTalk Configuration file?

    How can we send only one message to a WCF service at a time? How we can limit the number of concurrent calls to a WCF service without use the Singleton pattern or without do the change in BizTalk Configuration file? Can we do it by Host throttling?

    Hi Pawan,
    You need to use WCF-Custom adapter and add the ServiceThrottlingBehavior service behavior to a WCF-Custom Locations.
    ServiceThrottlingBehavior.MaxConcurrentCalls - Gets or sets a value that specifies the maximum number of messages actively processing across a ServiceHost. The MaxConcurrentCalls property specifies the maximum number of messages actively
    processing across a ServiceHost object. Each channel can have one pending message that does not count against the value of MaxConcurrentCalls until WCF begins to process it.
    Follow MSDN-
    http://msdn.microsoft.com/en-us/library/ee377035%28BTS.10%29.aspx
    http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentcalls.aspx
    I hope this helps.
    Rachit
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • (retain) properties in the singleton class

    Hi,
    What happens with the properties declared with (retain) in the singleton class:
    MyClass *foo;
    @property (nonatomic, retain) MyClass *foo;
    I am using a singleton class as explained http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFunda mentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW32 which should NOT be released.
    I see no way to call
    [foo release].
    My guess is that these properties will be allocated once and persist though entire life of the singelton - which is not a leak.
    correct?

    leonbrag wrote:
    My guess is that these properties will be allocated once and persist though entire life of the singelton - which is not a leak.
    correct?
    Yes. Of course, there are still ways to get rid of singletons if you really want/had to. In some cases, you could have a singleton that allocated system resources that aren't automatically released when a program ends. There are ways to clean up such things if you run across them. Look at the "applicationWillTerminate:" notification, for example.

  • EJB3 and/or Toplink and setting context for VPD

    We are looking at moving to the latest version of jdeveloper and taking advantage of the ejb3 and/or toplink features for the model part of applications. I have a question on how to set the vpd context using this new model. Currently we use:
    Jdeveloper 10.1.2.1
    Oracle application server 10g R2 Enterprise Edition ver 10.1.2.0.2
    OracleOCI driver
    Oracle 9i database
    Our database access is in regular java beans where we get a connection from the pool , set the context for the current user (by running a stored procedure on the connection) perform the required data access and then release the connection. It looks like when you use Toplink or EJBs with CMP the database access is out of the developer's control. How will I be able to set the context for each connection ( it's different for each user) once I move to the new model?

    Thank you. That looks like exactly what I need, at least for toplink. I have been told though, that since we are deploying to the OC4J container and it will manage persistence and since EJB 3 simplifies the creation of entity beans that we should use EJB 3 entity beans and a session facade for the model and not add toplink as it would be an extra layer we don't really need , would you agree?

  • Serializing a class that implements the Singleton pattern

    Hello,
    I am relatively new to Java and especially to serialization so the answer to this question might be obvious, but I could not make it work event though I have read the documentation and the article "Using XML Encoder" that was linked from the documentation.
    I have a class that implements the singleton pattern. It's definition is as follows:
    public class JCOption implements Serializable {
      private int x = 1;
      private static JCOption option = new JCOption();
      private JCOption() {}
      public static JCOption getOption() { return option; }
      public int getX() { return x; }
      public void setX(int x) { this.x = x; }
      public static void main(String args[]) throws IOException {
        JCOption opt = JCOption.getOption();
        opt.setX(10);
        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Test.xml")));
        encoder.setPersistenceDelegate(opt.getClass(),  new JCOptionPersistenceDelegate());
        encoder.writeObject(opt);
        encoder.close();
    }Since this class does not fully comply to the JavaBeans conventions by not having a public no-argument constructor, I have create a class JCOptionPersistenceDelegate that extends the PersistenceDelegate. The implementation of the instantiate method is as follows:
      protected Expression instantiate(Object oldInstance, Encoder out) {
           Expression expression = new Expression(oldInstance, oldInstance.getClass(), "getOption", new Object[]{});
            return expression;
      }The problem is that the resulting XML file only contains the following lines:
        <java version="1.5.0_06" class="java.beans.XMLDecoder">
            <object class="JCOption" property="option"/>
        </java> so there is no trace of the property x.
    Thank you in advance for your answers.

    How about this:
    import java.beans.DefaultPersistenceDelegate;
    import java.beans.Encoder;
    import java.beans.Expression;
    import java.beans.Statement;
    import java.beans.XMLEncoder;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    public class JCOption {
        private int x = 1;
        private static JCOption option = new JCOption();
        private JCOption() {}
        public static JCOption getOption() { return option; }
        public int getX() { return x; }
        public void setX(int x) { this.x = x; }
        public static void main(String args[]) throws IOException {
          JCOption opt = JCOption.getOption();
          opt.setX(10);
          ByteArrayOutputStream os = new ByteArrayOutputStream();
          XMLEncoder encoder = new XMLEncoder( os );
          encoder.setPersistenceDelegate( opt.getClass(), new JCOptionPersistenceDelegate() );
          encoder.writeObject(opt);
          encoder.close();
          System.out.println( os.toString() );
    class JCOptionPersistenceDelegate extends DefaultPersistenceDelegate {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            return new Expression(
                    oldInstance,
                    oldInstance.getClass(),
                    "getOption",
                    new Object[]{} );
        protected void initialize( Class<?> type, Object oldInstance, Object newInstance, Encoder out ) {
            super.initialize( type, oldInstance, newInstance, out );
            JCOption q = (JCOption)oldInstance;
            out.writeStatement( new Statement( oldInstance, "setX", new Object[] { q.getX() } ) );
    }   Output:
    <?xml version="1.0" encoding="UTF-8"?>
    <java version="1.5.0_06" class="java.beans.XMLDecoder">
    <object class="JCOption" property="option">
      <void property="x">
       <int>10</int>
      </void>
    </object>
    </java>

  • Singleton and non singleton in webdynpro java

    Hi All,
    where we use singleton and non singleton in webdynpro application.please send me with any example (scenario).
    Regards
    Anand

    Hello Anand,
    I think that your question is for u201CWeb Dynpro Javau201D forum..
    Please use the correct forum for your question.
    In general:: http://wiki.sdn.sap.com/wiki/display/WDJava/SingletonandNon-Singleton+Nodes
    There is example at : http://wiki.sdn.sap.com/wiki/display/WDJava/DynamicUIGeneration
    u201CWelcome to Web Dynpro Java! u201C  Wiki : http://wiki.sdn.sap.com/wiki/display/WDJava/WelcometoWebDynproJava%21
    Thank you and best regards, Natalia Khlopina

  • Singleton node and non singleton practical scenario

    Hi  Friends,
    Iam totally confused with singleton and non singleton node implementation please explain practical implementation on singleton and nonsingle ton node . In which scenario  non single ton node is used.
    Thanks in advance
    Prasad

    Hi,
    Singleton Node:
    A singleton node contains only one instace of the node at runtime. And that instace contains multiple elements at runtime.
    By default if we create a node under ROOT context node, it will be allways singleton true.
    Non singleton node:
    A non singeton node contains more then one node instance at runtime. And each instance contains multiple elements at runtime.
    It is not possible to create NonSingletonNodes directly under ROOT context node. We can create under any node which is under ROOT context node.
    Note: In terms of datastorage at runtime we can say if node is table then each elment of node instance is a row of that table.
    When is it requried to create non singleton nodes?
    For example if you have list of SalesOrders and each and every oder is having list of items. Then we can create this node structure in two ways:
    Orders (singleton true)
    > Items (singleton true)
    Here in this case at any point of time the there will be only one instance of Items node exist for currently selected element of Orders node. And that instance contains multiple elements nothing but items of that order.
    Orders (singleton true)
    > Items (singleton false)
    Here in this case at any point of time all the instances of Items node exist for all the elements(not only for currently selected element) of Orders node. And those instances contains multiple elements nothing but items of those corresponding orders.
    I hope it helps.
    Regards,
    Vijay K

  • HttpSession and HttpServlet singletons?

    Hi guys,
    I have here two questions for better understanding of the HttpSession and HttpServlet classes:
    1. Is the HttpSession object existing between the server and the client and used for data exchange a kind of singleton? E.g. if I call a servlet concurrently with different parameters (as shown above), will this conflict on evaluation of the session parameters on the servlet side?
    "...MyPage.jsp?attr1=1..."
    "...MyPage.jsp?attr1=2..."
    2. Is the Servlet itself ( "public class MyServlet extends HttpServlet{..." ) also a singleton? I.e. for the above described use case also a problem?
    Thanks.

    user13612505 wrote:
    Thanks so far!
    So if I understood right:
    1.There is always only one session per client. If several servlets or several instances of the same servlet >would write an attribute with the same name to the session, this would result in an undefined result (the
    llast written value would be saved, the previos values would be lost).This is usually desirable behaviour because session attributes are normally shared by many servlets. Attributes with different significance should clearly have different names.
    The solution for this would be: different attribute names for each servlet and before calling the same
    servlet on the client side, I have to wait until the previous request to this servlet is finished.I don't really understand what you're saying here. Normally a servlet will only set a session attribute if it's to be accessed by later transactions. The whole point of session attributes is to span multiple transactions for the same client.
    If you want to store an attribute for use in the same transaction (e.g. when you forward from Servlet to JSP) store it in a request attribute, not a session attribute.
    >
    2. I don't know when the application server (I'm using glassfish) creates a new instance of a servlet. So for this problem I would also have to wait on the client side (as described above).
    No, it shouldn't matter how many instances of the Servlet are created. In general Servlets are "stateless", you don't use instance fields at all.
    Servlets are "re-entrant", that is mulitple threads may use the same servlet object to process different transactions simultaneously. So it's crucial that a servlet doesn't change any of it's fields during the course of processing a transaction, and the best way to be sure is not to have any fields at all. (You could have fields that don't change, and initialise them in the init method or constructor).

  • Implementing the Singleton pattern

    Has anyone implemented the singleton pattern in Forte? A singleton is simply ensuring that there is one unique instance of a class. In other OO languages I would create a class method which would use a class variable to hold onto the unique instance. Since forte doesn't have either of these (class methods or variables), I'm not sure how to do it. I thought of using named objects, but it seems like a heavy implementation. Any ideas.

    An SO with its shared=TRUE and anchored=TRUE?
    Venkat J Kodumudi
    Price Waterhouse LLP
    Internet: [email protected]
    Internet2: [email protected]
    -----Original Message-----
    From: [email protected] [SMTP:[email protected]]
    Sent: Monday, February 02, 1998 1:09 PM
    To: Venkat Kodumudi
    Subject: Implementing the Singleton pattern
    To: [email protected] @ Internet
    cc:
    From: [email protected] @ Internet
    Date: 02/02/98 12:36:02 PM
    Subject: Implementing the Singleton pattern
    Has anyone implemented the singleton pattern in Forte? A singleton is
    simply
    ensuring that there is one unique instance of a class. In other OO
    languages I
    would create a class method which would use a class variable to hold
    onto the
    unique instance. Since forte doesn't have either of these (class
    methods or
    variables), I'm not sure how to do it. I thought of using named
    objects, but it
    seems like a heavy implementation. Any ideas.

  • The Singleton patter

    The Singleton pattern can ensure either only one instance of a class is ever created or that a fixed variable number of instances are created
    Is not singleton pattern provides one instance of the class ?
    I'm confused to read this +".. that a fixed *variable number of instances* are created"+
    Could you please post what does this mean ? Does that mean same instance been counted many times ? OR do they really create multiple instances sometimes in some situation ?

    user575089 wrote:
    A little example which is a part of the context.
    As part of the design, you need to ensure that only two instances of the 'Speaker' class are ever created (the speaker class is used to control the volume, bass, and tone)
    I think we can use Singleton here No, because Singleton means one instance. Not sure how to make that any clearer.
    but same reference can be used two times to represent two speaker . No. With a singleton, you will have ONE speaker object. It doesn't matter how may references to that object you have, it's still the same single object. And "using the same reference multiple times" is just meaningless.
    You want exactly two speaker objects, so your Speaker class needs to be a multiton that privately creates two instances, then provides access to them. One could view a Java enum as either a singleton or a multiton, depending on how many elements are defined for that enum.

  • I am trying to update Adobe Bridge and Photoshop CS6, because it is not opening my CR2 files taken by my Canon 6D.  I have tried to go to help updates, and the software says that it is "Up to Date".  However, if I view the plug-in, it says that Camera R

    I am trying to update Adobe Bridge and Photoshop CS6, because it is not opening my CR2 files taken by my Canon 6D.  I have tried to go to help > updates, and the software says that it is "Up to Date".  However, if I view the plug-in, it says that Camera Raw is only version 7.1.  I can not find a direct download for Camera Raw 7.3, only the DNG converter, NOT CAMERA RAW!  Please Help!

    Did you fix your issue?  I am having the same one

  • I have bought a film from itunes and the credit has come out of my account, but i can't find the film anywhere, it said it was downloading, then i left the laptop and on return i couldn't find the film. how do i find the film?

    i have bought a film from itunes and the credit has come out of my account, but i can't find the film anywhere, it said it was downloading, then i left the laptop and on return i couldn't find the film. how do i find the film?

    Maybe it is in the Purchased category of iTunes,
    Try going there

  • I am trying to restore my catalog having previously done a back up to an external hard drive and subsequently an incremental backup. I am using Photoshop Elements 11 and the only option given in the restore procedure is to open a .tly file.

    I have done this but now the restore function is asking for yet another file, which i assume to be the original back up, but that is the only .tly file since the only other relevant file appears to be called catalog.buc but that is just not visible when using the restore function? How do I continue from here with this restoration of my catalog?

    Martin_Had a écrit:
    Thank you Andaleeb. I appear to have an old backup of a year ago, and a more recent full back up plus an incremental backup.
    Regrettably I don't really understand what is going on because firstly the restore does not complete its cycle so I cannot see what that backup file contains and secondly all I have read would suggest that the .tly file is the full backup and the catalog.buc file is the incremental backup. For the present, the catalog shows the photos for 2014 which makes me think I might have backed from the old back up file.
    I am minded to create another catalog and try again.
    Any views on what I can do?
    A backup (full or incremental) is a folder, not a file. It contains renamed pictures file copies as well a copies of the files and subfolders of the original catalog. The catalog.buc is a renamed copy of the database of your original catalog while the backup.tly. That backup.tly file contains the information to restore the renamed pictures where you decide, the original location or a new custom one. You can't do anything with the backup yourself, only the restore process can do the job if it finds the backup.tly file. In the case of an incremental backup, you have to tell the restore process where to find the incremental backup folder; it finds the backup.tly file in that folder and finds what is to restore there; then it asks you for the previous backup folder (in your case the full backup); you then browse to that full backup folder so that the restore process can find find the backup.tly there; the restore then deals with the rest of the files to restore.

  • I am trying to import developed images from LightRoom 5 in o Photoshop 6.  I am receiving this message and the images will not open.....'Could not open scratch file because the file is locked, you do not have necessary access permissions or another progra

    I am trying to import developed images from LightRoom 5 Photoshop 6 for further editing.  I am receiving this message and the images will not open.....'Could not open scratch file because the file is locked, or you do not have necessary access permissions or another program is using the file.  Use the 'Properties' command in the Windows Explorer to unlock the file. How do I fix this?  I would greatly appreciate it if you would respond with terms and procedures that a computer ignorant user, such as me, will understand.   Thanks.

    Have you tried restoring the Preferences yet?

Maybe you are looking for

  • If you're NOT running Aperture 3.6 and want to update to 10.10.3 - read this FIRST.

    If you’re NOT running Aperture 3.6 and want to update to 10.10.3 - read this FIRST. In this personal scenario, I used a Mavericks (10.9) test hard drive to see what would happen if I updated to 10.10.3. No photos were harmed in the making of this pos

  • Licensing restrictions on RE-use of HP (small business) notebook HW components?

    Licensing restrictions on RE-use of HP (small business) notebook HW components? I realize that it is illegal to use some of the (OEM) software that was distributed with the refurbished HP nw8440 Mobile Pro Workstation (small business HP Compaq notebo

  • Different e-mail alerts for different contacts

    Can I have only certain e-mails alert me with a tone and let all others remain silent in iOS5? I use my phone for work and want to assign e-mails from specific people to audibly alert me and let all the rest remain silent so I'm not bothered by unimp

  • Airtunes still dropping out!

    I am still having trouble with my airtunes frequently dropping the signal to my speakers. When I pause the music and then start it again, it works. I have the most recent version of itunes. My computer is also very close to my airport express. What c

  • Install tiger over leopard?

    I have an iMac G5 with 2 gigs of ram and have noticed a very slow OS after installing Leopard (archive and install) over Tiger 10.4.10. I would like to just go back to Tiger and forget about Leopard, but is there a direct way to go back to Tiger with