如何配置JavaMelody以监视C3p0 DataSource中的Jdbc连接

时间:2018-01-17 07:39:26

标签: java spring jdbc c3p0 java-melody

我使用Spring配置文件配置C3P0。要监视DataSource,我按照javamelody的用户指南中的说明配置了$('.select-on-check-all, .checkbox-row').click(function(){ calculateNetto(); }) function calculateNetto() { var total_netto_send = 0; var total_netto_receive = 0; var netto_send = 0; var netto_receive = 0; for(var i=0; i < $('#checkbox.checkbox-row').length; i++) { if($('#checkbox.checkbox-row')[i].checked == true) { netto_send = document.getElementById('table-penerimaan-produksi').getElementsByTagName('tr')[i+1].getElementsByTagName('td')[6].innerHTML; netto_receive = document.getElementById('table-penerimaan-produksi').getElementsByTagName('tr')[i+1].getElementsByTagName('td')[5].innerHTML; netto_send = netto_send == "" ? 0 : Number(netto_send.split(",").join("")); netto_receive = netto_receive == "" ? 0 : Number(netto_receive.split(",").join("")); total_netto_send += netto_send; total_netto_receive += netto_receive; } } $('#realisasiproduksi-total_netto_send').val(total_netto_send); $('#realisasiproduksi-total_netto_receive').val(total_netto_receive); } 。但我的报告显示0个活动的jdbc连接,因为我的minPoolSize是10.我错过了什么?

net.bull.javamelody.SpringDataSourceFactoryBean添加了web.xml

monitoring-spring.xml

在Spring中,jdbc配置文件是:

   <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:net/bull/javamelody/monitoring-spring.xml,
   </param-value>
 </context-param>

我尝试将<bean id="sql2oDatasource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="#{dbProps['ops.jdbc.driverClassName']}"/> <property name="jdbcUrl" value="#{dbProps['ops.jdbc.url']}"/> <property name="user" value="#{dbProps['ops.jdbc.username']}"/> <property name="password" value="#{dbProps['ops.jdbc.password']}"/> <property name="maxPoolSize" value="#{dbProps['ops.c3p0.max_size']}" /> <property name="minPoolSize" value="#{dbProps['ops.c3p0.min_size']}" /> <property name="maxStatements" value="#{dbProps['ops.c3p0.max_statements']}" /> <property name="checkoutTimeout" value="#{dbProps['ops.c3p0.timeout']}" /> <property name="preferredTestQuery" value="SELECT 1"/> </bean> <!-- Configuring the session factory for SQL-2-O --> <bean id="sql2oSession" class="org.sql2o.Sql2o"> <constructor-arg ref="wrappedDBDataSource" /> <constructor-arg value="PostgreSQL" type="org.sql2o.QuirksMode" /> </bean> <bean id="wrappedDBDataSource" class="net.bull.javamelody.SpringDataSourceFactoryBean" primary="true"> <property name="targetName" value="sql2oDatasource" /> </bean> 作为DriverClass传递给数据源,将net.bull.javamelody.JdbcDriver传递为:{/ p>

driver

但是 <property name="properties"> <props> <prop key="driver">org.postgresql.Driver</prop> </props> </property> 驱动程序没有以这种方式注册。

1 个答案:

答案 0 :(得分:0)

根据documentation,您的配置看起来不错。您会在报告中看到数据库活动连接,池大小值,这也意味着您的配置正常。

另一方面,活动数据库连接计数表示来自数据库连接池的连接数与当时的数据库连接的数量。 0活动连接对您有好处(如果您的应用程序正常工作)。这意味着您的数据库操作很快就完成了。当数据库操作很快时,很难捕获活动连接。