13 Replies Latest reply on May 28, 2011 6:27 PM by Leo van den berg

    I might have found a the bug of seam2.2

    chen qiang Newbie
      My English is not good, please read my description,thanks!




      When I query the database once, will add a daemon thread.Performance testing will have problems,Code is very simple,there are 2 sample code like this:


      CODE 1:

      @In EntityManager entityManager;

      return entityManager.createQuery(''from User'').getResultList();

      ......





      CODE 2:

      @In IdentityManager identityManager;

      return identityManager.authenticate(usernmane,password);



      Run jconsole will see the thread 9,click thread 9 will see that block amount and waiting amount is IS GROWING......

      LIKE THIS:

      name: Thread 9

      Status: TIMED WAITING com.arjuna.ats.arjuna.coordinator.TransactionReaper@bd32cc

      block amount:31  waiting amount:31


      Stack trace:

      java.lang.Object.wait(Native Method)
      com.arjuna.ats.internal.arjuna.coordinator.ReaperThread.run(ReaperThread.java:98)

        • 1. Re: I might have found a the bug of seam2.2
          Leo van den berg Master

          Hi,


          can you show the full code listing of the bean(s), because this is very unclear for me.


          Leo

          • 2. Re: I might have found a the bug of seam2.2
            chen qiang Newbie

            This problem has nothing to do with the codes, either write your own code or seam own components, just use entityManager will be such a problem

            • 3. Re: I might have found a the bug of seam2.2
              Leo van den berg Master

              Hi,


              with all my respect, if you state there is a bug in Seam and ask our opinion, we only want some additional feedback, If you create a JIRA for this issue they will ask the same.


              I think I have a tiny bit more experience with Seam as you have and in my 3 years of experience with different versions of Seam I have never seen this behaviour with an entityManager and I can only conclude that you're not using things as it should be done.


              If you want us to take you serious be a bit more cooperative and ahow what you are doing.



              Leo


              P.S. I have to deal on a daily basis with newbies and they first thing everybody shouts if things don't work is blame the technology instead of their own lack of knowledge.

              • 4. Re: I might have found a the bug of seam2.2
                chen qiang Newbie
                hi,Leo,
                Thank you for your reply, I've listed some of my codes, maybe you can help me find the problem




                this is my base class GenericService

                public class GenericService implements Serializable {
                
                     private static final long serialVersionUID = 1149585747344636336L;
                     protected ValueExpression<EntityManager> entityManager;
                     protected void init() {
                          if (entityManager == null) {
                               entityManager = Expressions.instance().createValueExpression("#{entityManager}", EntityManager.class);
                          }
                     }
                     protected EntityManager lookupEntityManager() {
                          return entityManager.getValue();
                     }
                     
                     protected void persistEntity(Object entity) {
                          lookupEntityManager().persist(entity);
                     }
                
                     protected Object mergeEntity(Object entity) {
                          return lookupEntityManager().merge(entity);
                     }
                
                     protected void removeEntity(Object entity) {
                          lookupEntityManager().remove(entity);
                     }
                
                
                }
                



                my service class extends GenericService
                @Name("security.business.service.ExtendSecurityManager")
                @Scope(ScopeType.APPLICATION)
                public class ExtendSecurityManager extends GenericService implements IExtendSecurityMananger{
                
                     private static final long serialVersionUID = -8703268375175870560L;
                
                     @Logger
                     private Log log;
                
                     @Create
                     public void init() {
                          super.init();
                     }
                     public List<User> findUserByDivisionId(Integer divisionId) throws DataAccessException {
                          try {
                               String hql = "from User u where u.division.divisionId=" + divisionId;
                               Query accountQuery = lookupEntityManager().createQuery(hql);
                               List<User> list = accountQuery.getResultList();
                               List<User> temp = new ArrayList<User>();
                               if (null != list && list.size() > 0)
                                    for (User each : list)
                                         temp.add(each);
                               return temp;
                          } catch (Exception e) {
                               log.debug("find users failed!", e);
                               throw new DataAccessException("find users failed!", e.getCause());
                          }
                     }
                
                     public String findDivisionNameDivisionId(Integer divisionId) throws DataAccessException {
                          try {
                
                               Division division = (Division) lookupEntityManager().find(Division.class, divisionId);
                               return division.getDivisionName();
                          } catch (Exception e) {
                               log.debug("find division name failed", e);
                               throw new DataAccessException("error!", e.getCause());
                          }
                     }
                
                ......more method........
                

                • 5. Re: I might have found a the bug of seam2.2
                  Leo van den berg Master

                  Hi,


                  That is what was needed to get the picture right!


                  First of all: Getting an EntityManager is MUCH simpler as you think.You just use the In annotation in your class. If you entitymanagerfactory is configured correctly (!!!), you just use:





                  public class ExtendSecurityManager extends GenericService implements IExtendSecurityMananger{
                  
                       private static final long serialVersionUID = -8703268375175870560L;
                  
                       @Logger
                       private Log log;
                  
                          @In EntityManager entityManager;
                  
                       @Create
                       public void init() {
                            super.init();
                       }
                  
                         ..... The rest of the class
                  



                  Additionally I assume that you need this service when your system starts and it must be active before something takes place, so you need additional annotations for Startup and AutoCreate and it depends on the rpesence of the persistency environment, so you need some additional puzzling. Although the class is at ApplicationScope this is NOT necessary, you can do all lookups directly in EventScope. Because you basically want it to get Permissions, read the chapter on Permissions in the Seam docs, which is able to do the things you want.


                  Besides the lookup of the entityManager, saving and retrieving won't work so you need some re-designing over there also !



                  Leo



                  P.S: Be open minded and don't blame the technology, Seam is pretty complex and overwhelming and you need a thorough knowledge of dependency injection, persistency, conversations etc.









                  • 6. Re: I might have found a the bug of seam2.2
                    chen qiang Newbie

                    Hi,


                    Thanks again for your reply

                    I tried many ways to get an EntityManager ,including what you told me:




                    1.@In EntityManager entityManager;
                    2.EntityManager entityManager=(EntityManager )Component.getInstance(EntityManager .class, true);
                    3.@PersistenceContext(unitName="entityManager")/**used on session bean*/
                       EntityManager entityManager;  
                    4.Expressions.instance().createValueExpression("#{entityManager}", EntityManager.class).getValue();



                    All four methods can work properly,entitymanagerfactory is configured correctly.




                    I have tried  my service on ApplicationScope、SessionScope 、EventScope and Stateless,

                    No matter which method I use ,for each query the database will have a blocking or waiting daemon thread




                    I refer to the JpaIdentityStore and IdentityManager(seam components) ,and redesign my code, but did not work.



                    The fourth way to get an EntityManager is from JpaIdentityStore,JpaIdentityStore is on ApplicationScope


                    Now I'm doing performance testing, stress testing 120 people can only run one day,
                    because the daemon thread is growing.

                    I guess entityManager might not thread-safe








                    chenqiang


                    • 7. Re: I might have found a the bug of seam2.2
                      Leo van den berg Master

                      Hi,


                      are you sure everything is configured correctly. I assume you're using Hibernate's JPA provider.
                      Be aware that at the moment you use an Application Scoped bean, everything runs with the same entityManager and if you have 120 users attacking the same bean, you will run in problems. This is no difffernt than whatever web application when you use vars in the Application context.


                      If it is basically a permission manager, look at the way it is implement in the differnt Seam components.


                      Leo

                      • 8. Re: I might have found a the bug of seam2.2
                        chen qiang Newbie
                        leo ,thank you every much,Your reply shows me the direction,thanks again




                        I'm doing is a single sign-on system, the system needs a high performance,I only used seam one year, not know much about it.



                        so I'm really not sure my configuration is correct,I have listed blow


                        my components.xml,Problem may be here

                        
                        <transaction:ejb-transaction/>
                           <persistence:managed-persistence-context name="entityManager" auto-create="true"
                                              persistence-unit-jndi-name="java:/SECEntityManagerFactory"/>
                            <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
                            <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="false"/>
                            <security:jpa-identity-store 
                               user-class="....mypackage..User"
                               role-class="...mypackage..Role"
                               />
                            <security:jpa-permission-store user-permission-class="..mypackage..Permission"/>
                        


                        my dev-ds.xml

                        
                        <datasources>
                        
                             <xa-datasource>
                                  <jndi-name>SECDatasource</jndi-name>
                                  <track-connection-by-tx>true</track-connection-by-tx>
                                  <isSameRM-override-value>false</isSameRM-override-value>
                                  <managedconnectionfactory-class>
                                       org.jboss.resource.adapter.jdbc.xa.oracle.XAOracleManagedConnectionFactory
                            </managedconnectionfactory-class>
                                  <transaction-isolation></transaction-isolation>
                                  <max-pool-size>300</max-pool-size>
                                  <min-pool-size>20</min-pool-size>
                                  <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
                                  <xa-datasource-property name="URL">jdbc:oracle:thin:@100.100.29.200:1521:cis</xa-datasource-property>
                                  <xa-datasource-property name="User">iums</xa-datasource-property>
                                  <xa-datasource-property name="Password">admin</xa-datasource-property>
                                  <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
                             </xa-datasource>
                        
                        </datasources>
                        


                        my persistence-dev.xml


                        
                        <?xml version='1.0' encoding='UTF-8'?>
                        <!-- Persistence deployment descriptor for dev profile -->
                        <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
                                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
                                     version="1.0">
                           <persistence-unit name="SEC" >
                           
                              <provider>org.hibernate.ejb.HibernatePersistence</provider>
                              <jta-data-source>java:SECDatasource</jta-data-source>
                             
                              <properties>
                                 <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
                                 <property name="hibernate.hbm2ddl.auto" value="none"/><!-- create -->
                                 <property name="hibernate.show_sql" value="false"/>
                                 <property name="hibernate.format_sql" value="true"/>
                                 <!-- property name="hibernate.default_schema" value="${hibernate.default_schema.uppercase}"/> -->
                                 <property name="jboss.entity.manager.factory.jndi.name" value="java:/SECEntityManagerFactory"/>
                              </properties>
                           </persistence-unit>
                        
                            
                        </persistence>
                        


                        • 9. Re: I might have found a the bug of seam2.2
                          Leo van den berg Master

                          Hi,


                          I don't see anythin strange in your configuration, so it should work. Clean up (delete) the APP-server directories (DATA, TMP and WORK) and delete server.log from the LOG directoty.
                          This gives you a clean start, so it easier to read the produced log to see if teher are some hidden errors or warnings.


                          The best thing to do is to take the original Seam components and extend these to add your needed functionaly. The Seam beans are thoroughly tested my the dev-team and the users, so these work without a problem.


                          Leo


                          • 10. Re: I might have found a the bug of seam2.2
                            chen qiang Newbie
                            Problem may be a relationship with jboss-5.1.0.GA

                            Status: TIMED WAITING
                            com.arjuna.ats.arjuna.coordinator.TransactionReaper@bd32cc

                            block amount:31 waiting amount:31


                            Stack trace:

                            java.lang.Object.wait(Native Method) com.arjuna.ats.internal.arjuna.coordinator.ReaperThread.run(ReaperThread.java:98)


                            This may be the problem of jboss configuration about transaction ,but I do not know how to solve.googled it, but got nothing.

                            • 11. Re: I might have found a the bug of seam2.2
                              Leo van den berg Master

                              Hi,


                              You can change settings in transaction management of JBOSS in the deploy dir you can find the files there (they start with transaction).


                              You can change things like timeout etc.


                              Leo

                              • 12. Re: I might have found a the bug of seam2.2
                                chen qiang Newbie
                                hi,Leo,the problem about EntityManager was solved,should be life-cycle issues,

                                performance of the system has been improved,But still did not meet the requirements




                                  I found a new problem, when I load or refresh a page, even though the page is used to display some static messages, thread blocking issue occurs, it may be the issue on the JSF life cycle,The same phenomenon with entityManager issue:


                                TIMED WAITING in com.arjuna.ats.arjuna.coordinator.TransactionReaper@170604f


                                I found this question online, but did not find a solution.


                                Any idea, Thanks in advance.


                                chenqiang

                                • 13. Re: I might have found a the bug of seam2.2
                                  Leo van den berg Master

                                  Hi,


                                  I am not a DB-expert (I always fall back on the real experts there), but there are also the (Hibernate) settings you can add to persistence.xml I know the Hibernate doc explains in depth the different parameters you can add/set.


                                  Leo