4 Replies Latest reply on Aug 25, 2001 11:51 PM by marc fleury

    just one instance of a stateful session bean

    Ralph Hesse Newbie


      I am trying to configure the container (Jboss 2.2.2) to instantiate no more than one instance of a stateful session bean. Unfortunately the container is creating more than one instance. Which I do not want, because the bean is meant to open a serial connection to a cellular phone.
      Any suggestions???

      Ralph Hesse
      below is the jboss.xml configuration which I used!!!!!!!

      <?xml version="1.0" encoding="Cp1252"?>

      <configuration-name>Standard Message Driven Bean</configuration-name>

      <configuration-name>SMSMessage Stateful SessionBean</configuration-name>


      <container-name>SMSMessage Stateful SessionBean</container-name>
      <!-- CMT
      <!-- BMT

        • 1. Re: just one instance of a stateful session bean
          Noel Hebert Newbie


          The creation of Singletons is a bit of a problem
          in the J2EE/EJB context. No matter what you do
          if you get it to work it will be app server dependent.

          Maybe you need to step out of the EJB container context
          and use JMX MBeans, Jini or stand-alone Java programs
          that register themselves with a JBoss JNDI namespace.

          I have no idea what you are trying to do, but sometimes
          it pays to think outside of "The Box"...



          • 2. Re: just one instance of a stateful session bean
            Ralph Hesse Newbie


            I solved it meanwhile with a interprocess communcation throw a static variable in the session bean. I think I read something that static variables are not allowed in ejb´s, but I am not sure. However it works. I block the other beans as long as my resource is busy.
            Hopefully this works, it is just a temporary solution and so I think it is ok.


            • 3. Re: just one instance of a stateful session bean
              Noel Hebert Newbie


              Glad to see that you have found a solution
              that meets your immediate needs.

              However, you are quite correct in noting that
              the use of static variables are not allowed.
              There use is frought with peril.

              It may work, but just remember that it is not
              portable and will not scale into a clustered
              (multi-application server) environment.

              If your application is running in a single JBoss
              instance (or any app server) and it meets your
              performance needs, than go for it.

              But be warned...



              • 4. Re: just one instance of a stateful session bean
                marc fleury Master

                Let me get this straight... one instance of a stateful bean?... hmmmm sounds like an entity bean to me :)

                in any case it seems you are trying to map something to ejb that doesn't quite fit, the static idea is a good one and frankly the only thing that will throw it off is the passivation of the stateful bean, just make sure you use non-passivating caches or that the bean implements passivate and activate correctly.

                But the most enterprise ready way of doing this is the MBean way... try to dig that if you have time