Announcement Announcement Module
Collapse
No announcement yet.
Connection pooling Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connection pooling

    I can't tell if I have my connection pooling setup right or not. Does anyone know how to test this?

    The behavior I'm seeing is this. If I have my number of initial poolable connections set to 1. It will always remain 1 (the max is 8), I'll never see a new connection started no matter how repeatedly I click refresh (I would expect it to add more, but maybe not). If I raise the number of initial threads to 4, it will start me with 4 and if I repeatedly click refresh I'll see that they seem to be being used at different times (some of the sleep values will reset like they've recently been used) and then they all go back to sleep. They never timeout and I still never see new one's created.

    It doesn't seem like I ever run out of connections in my pool, but it might just be because it's only ever using one connection.

    Below is my persistence.xml file:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:p="http://www.springframework.org/schema/p" 
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	   		http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    	   		http://www.springframework.org/schema/context
    	   		http://www.springframework.org/schema/context/spring-context-3.1.xsd
    			http://www.springframework.org/schema/mvc 
    			http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
    			http://www.springframework.org/schema/tx
                http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    			http://www.springframework.org/schema/aop 
                http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
    
       <bean id="myDataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
          <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
          <property name="url" value="jdbc:mysql://localhost:3306/xxxxxxx"/>
          <property name="username" value="xxxxxx"/>
          <property name="password" value="xxxxxx"/>
          <property name="initialSize" value="1" />
          <property name="maxActive" value="8" />
          <property name="maxIdle" value="8" />
          <property name="maxWait" value="10000" />
          <property name="removeAbandoned" value="true" />
          <property name="removeAbandonedTimeout" value="60" />
          <property name="logAbandoned" value="true" />
       </bean>
    
       <bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
          <property name="dataSource" ref="myDataSource"/>
          <property name="annotatedClasses">
    	     <list>
    		    <value>watchmejava.blog.model.BlogPost</value>
    		    <value>watchmejava.blog.model.User</value>
    		    <value>watchmejava.blog.model.Comment</value>
    	     </list>
          </property>
          <property name="hibernateProperties">
             <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.max_fetch_depth">3</prop>
                <prop key="format_sql">true"</prop>
                <prop key="use_sql_comments">true</prop>
             </props>
          </property>
       </bean>
       
       <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
          <property name="sessionFactory" ref="mySessionFactory" />
       </bean>
       
       <tx:annotation-driven transaction-manager="txManager"/> 
       
       <bean id="BlogDAOImpl" class="watchmejava.blog.persistence.BlogDAOImpl">
           <property name="factory" ref="mySessionFactory" />
       </bean>
       <bean id="UserDAOImpl" class="watchmejava.blog.persistence.UserDAOImpl">
           <property name="factory" ref="mySessionFactory" />
       </bean>
       <bean id="CommentDAOImpl" class="watchmejava.blog.persistence.CommentDAOImpl">
           <property name="factory" ref="mySessionFactory" />
       </bean>
               
    </beans>
    Is this how it's supposed to work or do I have something incorrect in my setup?

    Thanks in advance.

  • #2
    There is nothing wrong with it.

    Why should a refresh trigger a new connection? The page is rendered after that the connection is available again. If you really want to test it you need to do some load testing and that is not something you do by pressing refresh in your single browser.

    Comment

    Working...
    X