C3p0 connection pool monitor

View: New views
3 Messages — Rating Filter:   Alert me  

C3p0 connection pool monitor

by wmayuresh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi all,
I wanted to monitor connection pool created using c3p0.
So, I wrote a jsp to get ref to datasource as below:
<%!
WebApplicationContext wac = null;
ComboPooledDataSource ds = null;
public void jspInit()
{
        wac = WebApplicationContextUtils
        .getRequiredWebApplicationContext(getServletContext());
        ds = (ComboPooledDataSource)wac.getBean("dataSource");
}


%>
and i looked at:
<p align="center"><%=ds.getNumBusyConnectionsAllUsers()%></td>

to get current number of connections in the pool.
I just refresh to get the current no. Is this correct mechanism? because, I'm not getting expected results and I'm not sure if it is issue with way I'm getting conn pool current size or othe rpart of app.
I'm using spring-hiberrnate.
My data source properties are:
<bean id="dataSource"
                class="com.mchange.v2.c3p0.ComboPooledDataSource"
                destroy-method="close">
                <property name="driverClass">
                        <value>oracle.jdbc.driver.OracleDriver</value>
                </property>
                <property name="jdbcUrl">
                        <value>jdbc:oracle:thin:@(DESCRIPTION=(ENABLE=BROKEN)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=myservice)))</value>
                </property>
                <property name="properties">
                        <props>
                                <prop key="c3p0.acquire_increment">2</prop>
                                <prop key="c3p0.idle_test_period">100</prop>
                                <prop key="c3p0.max_size">20</prop>
                                <prop key="c3p0.max_statements">0</prop>
                                <prop key="c3p0.min_size">2</prop>
                                <prop key="user">myuser</prop>
                                <prop key="password">password</prop>
                        </props>
                </property>
        </bean>

Re: C3p0 connection pool monitor

by anyz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Re: C3p0 connection pool monitor

by wmayuresh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks anyz.

Last time, I tried this, it was not working. Now, worked. Might be, I was missing some configuration at that time.

Additionally, it gives thread details.

However, when compared with my jsp results with this tool, those are matching. So, my method use looks correct. I just want to confirm that, I should look at numBusyConnectionsAllUsers attribute for current connections in pool.