2 Replies Latest reply on Dec 16, 2014 9:33 AM by realcrazybird

    Single instance of Session EJB using EJB 2.1 on JBOSS 5.1.1 EAP

    realcrazybird

      Hello!

       

      In our project we're using quite old infrastructure and technlogy - EJB2.1  on a JBOSS 5.1.1 EAP and we don't have the time or budget to upgrade to EJB 3.0 or later.

       

      I'm using a MDB to process messages form a message queue. This message queue delegates work to a stateless session bean which creates objects in the database. Now I do have concurrency problems when the program runs (hibernate tries to create different Objects with the same primary key/id) and I want to ensure that there can only bw one instance of the EJB, which creates the objects.

       

      I tried to modify my jboss.xml (which is packaged in my META-INF dir in the ejb-jar) in the following way (changes in bold font)

       

      <?xml version="1.0"?>

      <jboss xmlns="http://www.jboss.com/xml/ns/javaee"

             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

             xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee

                                 http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"

             version="3.0">

          <enterprise-beans>

              <message-driven>

                  <ejb-name>AMessageBean</ejb-name>

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

                  <resource-adapter-name>activemq-rar-5.2.0.rar</resource-adapter-name>

       

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

                 

              </message-driven>

              <session>

                  <ejb-name>ASessionBean</ejb-name>

                  <local-jndi-name>local/ASessionBean</local-jndi-name>

                  <pool-config>

                      <pool-max-size>1</pool-max-size>

                  </pool-config>

              </session>

          </enterprise-beans>

      </jboss>

       

      but JBOSS seems to ignore this setting. Changing the "Standard Stateless SessionBean" container-configuration in the standardjboss.xml is not an options because I have other EJBs in the same applications which should not be limited to one instance at a time.

       

      I would be thankful for any tips.

       

      Stefan

        • 1. Re: Single instance of Session EJB using EJB 2.1 on JBOSS 5.1.1 EAP
          jaysensharma

          In  "$JBOSS_HOME/docs/dtd/jboss_5_0.dtd"  i see an option to define the "container-configuration"  for individual session beans using jboss.xml something as following to override container provided settings.      I did not  test it though but it can be seen in doc [1].

           

          <?xml version="1.0" encoding="UTF-8"?>
          <jboss xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee  http://www.jboss.org/j2ee/schema/jboss_5_1.xsd" version="5.1">
            <enterprise-beans>
                <session>
                  <ejb-name>HelloSLSB</ejb-name>
                    .
                    .
                  <configuration-name>Individual SLSB Config</configuration-name>
                    .
                    .
                </session>
            </enterprise-beans>
          
          <!-- Overriding container configuration -->
            <container-configurations>
                <container-configuration extends="Standard Stateless SessionBean">
                  <container-name>Individual SLSB Config</container-name>
                  <container-pool-conf>
                    <MaximumSize>20</MaximumSize>
                  </container-pool-conf>
                </container-configuration>
            </container-configurations>
          </jboss>
          

           

          [1] 11.3.1.3. Container configuration information   Says: 

          By placing a jboss.xml file in the EJB JAR META-INF directory, you can specify either overrides for container configurations in the standardjboss.xml file, or entirely new named container configurations. This provides great flexibility in the configuration of containers.

          • 2. Re: Single instance of Session EJB using EJB 2.1 on JBOSS 5.1.1 EAP
            realcrazybird

            Thanks, tried that but it seems that "container-configurations" is in the DTD but not in the Schema Definition. Why?