Hello,
It is not a new problem, I have seen this problem in a lot of forum but I did not found a clear answer in these forums.
I am using :
MySql 4.0.18
Hibernate 2.1.2
connector/j 3.0.11
JBoss 3.0.8
I simulate around 120 concurrent users. Each user is simulated by a Java Thread. When I looking to MySql administrator I have around 100 connection open. I did for these users a small request at first to try to identify the problem. I suspect that I forgot something in the configuration of Hibernate.
1- the SessionFactory is obtain from the JDNI (lookup) for the first user and keep in a static variable. So one lookup is done for all the users.
2- I open a session (openSession())
3- I do my request
4- I close my session (close())
The set up of hibernate is done with a JBOSS service (MBean).
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService"
name="jboss.jca:service=Hibernate">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss:service=Naming</depends>
<depends>jboss.jca:service=LocalTxCM,name=MySqlDS</depends>
<depends>jboss.j2ee:jndiName=ejb/util/SequenceGen,service=EJB</depends>
<attribute name="MapResources">mappings/controller.hbm.xml,mappings/lamsld.hbm.xml,mappings/content.hbm.xml</attribute>
<attribute name="JndiName">java:/HibernateFactory</attribute>
<attribute name="Datasource">java:/MySqlDS</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">java:/UserTransaction</attribute>
</mbean>
</server>
The connection pool set up is done in a JBOSS service (mysql-service.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<server>
<!-- ==================================================================== -->
<!-- New ConnectionManager setup for mysql using 2.0.11 driver -->
<!-- Build jmx-api (build/build.sh all) and view for config documentation -->
<!-- ==================================================================== -->
<mbean code="org.jboss.resource.connectionmanager.LocalTxConnectionManager" name="jboss.jca:service=LocalTxCM,name=MySqlDS">
<depends optional-attribute-name="ManagedConnectionFactoryName">
<!--embedded mbean-->
<mbean code="org.jboss.resource.connectionmanager.RARDeployment" name="jboss.jca:service=LocalTxDS,name=MySqlDS">
<attribute name="JndiName">MySqlDS</attribute>
<attribute name="ManagedConnectionFactoryProperties">
<properties>
<config-property name="ConnectionURL" type="java.lang.String">jdbc:mysql://localhost/lams</config-property>
<config-property name="DriverClass" type="java.lang.String">com.mysql.jdbc.Driver</config-property>
<!--set these only if you want only default logins, not through JAAS -->
<config-property name="UserName" type="java.lang.String">shwaa</config-property>
<config-property name="Password" type="java.lang.String">pshwaa</config-property>
</properties>
</attribute>
<depends optional-attribute-name="OldRarDeployment">jboss.jca:service=RARDeployment,name=JBoss LocalTransaction JDBC Wrapper</depends>
</mbean>
</depends>
<depends optional-attribute-name="ManagedConnectionPool">
<!--embedded mbean-->
<mbean code="org.jboss.resource.connectionmanager.JBossManagedConnectionPool" name="jboss.jca:service=LocalTxPool,name=MySqlDS">
<attribute name="MinSize">20</attribute>
<attribute name="MaxSize">180</attribute>
<attribute name="BlockingTimeoutMillis">5000</attribute>
<attribute name="IdleTimeoutMinutes">15</attribute>
<attribute name="Criteria">ByContainer</attribute>
</mbean>
</depends>
<depends optional-attribute-name="CachedConnectionManager">jboss.jca:service=CachedConnectionManager</depends>
<depends optional-attribute-name="JaasSecurityManagerService">jboss.security:service=JaasSecurityManager</depends>
<attribute name="TransactionManager">java:/TransactionManager</attribute>
<!--make the rar deploy! hack till better deployment-->
<depends>jboss.jca:service=RARDeployer</depends>
</mbean>
</server>
My questions are :
1) Do I need to do a special set up with Hibernate ?
2) How Hibernate now that it must used the connection pool ?
3) Can I use JBoss connection pool with Hibernate ?
4) What is the role of connector/j in that process ?
I not sure that I am clear, but I have the feeling that I forgot to specify something in the configuration files somewhere.
Any help would be appreciate, I have already asked two questions in this forum, and I have received a good answer each time. So I know that there are some really good programmers in this forum and I am confident to have an answer.
Thanks.
|