7 Replies Latest reply on Nov 19, 2002 5:52 AM by tux2

    OutOfMemoryError after 493 creates

    tux2

      Hi!
      We just tried to insert 5000 Enities of "BelegPosition" into the Database using the BelegPositonEB Entity Bean.
      A BelegEB Entity Bean has many BelegPositonEB Beans (1:N Relation) realized with CMR(EJB2.0, JBoss 3.03 with integrated Tomcat, WinNT40, P3 1000, 512MB).
      JBoss stops with the following OutOfMemoryError after creating/inserting the exact Number of 493 BelegPositionEB's.
      What's our problem?
      What could be wrong with our JBoss configuration? I suppose JBoss can handle more than 493 Beans?
      I'm happy for every hint.
      Thanks
      Stefan


      11:36:57,291 ERROR [LogInterceptor] TransactionRolledbackLocalException, causedBy:
      javax.ejb.EJBException: Unexpected Error
      java.lang.OutOfMemoryError

      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:205)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:203)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.ja
      va:301)
      at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
      at $Proxy85.addBelegPos(Unknown Source)
      at jbosstest.BelegSBBean.addNewPosition(BelegSBBean.java:99)
      at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionConta
      iner.java:660)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionI
      nterceptor.java:186)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstance
      Interceptor.java:77)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:203)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:313)
      at org.jboss.ejb.Container.invoke(Container.java:712)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:381)
      at sun.reflect.GeneratedMethodAccessor53.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:536)
      11:36:57,341 ERROR [STDERR] javax.ejb.TransactionRolledbackLocalException: Unexpected Error
      java.lang.OutOfMemoryError
      ; CausedByException is:
      Unexpected Error
      java.lang.OutOfMemoryError
      11:36:57,351 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTx
      Interceptor.java:224)
      11:37:00,395 ERROR [LogInterceptor] Unexpected Error:
      java.lang.OutOfMemoryError


      Here are parts of the code:
      /** ----------- Client.java ----------------------------------------*/
      //Client that invokes the SessionBean:
      ...
      try{
      belegSB.loadBeleg(new Integer("12345"));
      logger.debug("loaded Beleg");
      for (int i=1;i<5000;i++)
      {
      logger.debug("------ Start new Belegposition -------------");
      belegSB.addNewPosition(new Integer("154446"),"Maschine",new Integer("123"));
      logger.debug("createt pos: " + i);
      logger.debug("------ End new Belegposition -------------");
      }
      }
      catch (Exception ex){
      ex.printStackTrace();
      }
      ...

      /** ----------- BelegSB.java (SessionBean) -------------------------*/
      public void addNewPosition(Integer artikelNr, String artikelBez, Integer artikelPreis) throws BelegException {
      ...

      belegEB.addBelegPos(artikelNr,artikelBez,artikelPreis);
      ...
      }

      /** ----------- BelegEB.java (EntityBean) -------------------------*/
      ...
      // CMR-Fields 1:N Relation (BelegEB:BelegPositionenEB)
      public abstract void setBelegPositionenEB(java.util.Collection belegPositionenEB);
      public abstract java.util.Collection getBelegPositionenEB();

      ...

      public void addBelegPos(Integer artikelNr, String artikelBez, Integer artikelPreis) {

      if(getBelegPositionenEB() == null) {

      setBelegPositionenEB(new ArrayList());
      }
      try {

      getBelegPositionenEB().add(belegPosEBHome.create(artikelNr,artikelBez,artikelPreis));

      }
      catch (CreateException ex) {
      logger.info("BelegEBBean : " + ex.getMessage());
      }

      }


        • 1. Re: OutOfMemoryError after 493 creates
          scoy

          Give the VM more memory to run in.

          In unix, we just use:

          bash$ JAVA_OPTS="-Xmx512M" bin/run.sh

          You need to do the same thing in NTish :)

          Steve

          • 2. Re: OutOfMemoryError after 493 creates
            tux2

            I did!
            I gave the JVM 256m and it worked well for 1784 creates.
            Than the same errror occured!
            That can't be the solution. What should I do, if I want to insert 10000 or more entities?
            Is't JBoss able to handle with amounts like that?
            There must be a more appropriate solution.

            Stefan

            • 3. Re: OutOfMemoryError after 493 creates
              scoy

              We have code in production now that successfully creates 10000 beans (with CMR) in a single transaction, while running with the JVM set to 512m, so it can definitely be done.

              Maybe you need to do some profiling?

              Steve

              • 4. Re: OutOfMemoryError after 493 creates
                scoy

                I think I recall what is happening here now.

                The default cache size (set in the container configuration in conf/standardjboss.xml) is set to 1000000 beans.

                This means that JBoss is trying to cache each entity that you create.

                So try playing with the <container-cache-conf> elements in standardjboss.xml, or create your own in your jboss.xml file.

                Steve

                • 5. Re: OutOfMemoryError after 493 creates
                  taiwubrian

                  Hi, Steve,

                  I think you just gave me an answer to a problem I had for a while. Digesting discussions from another thread, I think followings are what to be done to avoid the OutofMemoryError. Please verify.
                  1. set the element max-capacity in standarjboss.xml to fit the size of the memory.
                  2. set the element max-capacity under cache-policy-conf for each bean in jboss.xml. There are trade-offs among beans.
                  3. set JAVA_OPS.

                  Are there more technics?

                  Best Regards,

                  Brian

                  • 6. Re: OutOfMemoryError after 493 creates
                    scoy

                    In general, we have found 2 & 3 the things to do.

                    As you tune your app, you gradually get more and more custom bean configurations.

                    Steve

                    • 7. Re: OutOfMemoryError after 493 creates
                      tux2

                      Hi Steve,
                      thanks for your hint. I reduced the default cache-size and it worked. But this was'nt the real problem. We found out, that the Solid database has problems dealing with transactions with more than 500 sql statements, because Solid works with a "bonsai-tree" memory management which holds the whole transaction in memory. This is necessary for the rollback mechanism.

                      Stefan