Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi there,
I have created a simple, synchronous Web Service which reads records out of a database, processes them and returns some values.
For the data fetching part, I used a tOracleInput component.
But I have the feeling that every request leads to the web service opening a new connection to the DB, fetching rows, and closing the DB connection. Is that correct?
If so: how can I avoid such overhead and use a connection pool (which automatically restores a DB connection if it has been lost)?
Thanks
Matt
<?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:osgi="http://www.springframework.org/schema/osgi"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- The Connection Pool -->
<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/demo"/>
<property name="username" value="talend"/>
<property name="password" value="talend"/>
<property name="initialSize" value="4"/>
<property name="maxActive" value="30"/>
<property name="maxIdle" value="10"/>
<property name="maxWait" value="3000"/>
<property name="validationQuery" value="SELECT 1"/>
</bean>
<!-- Publish the pool as an OSGi and JNDI Service -->
<osgi:service interface="javax.sql.DataSource" ref="mysql-ds">
<osgi:service-properties>
<entry key="osgi.jndi.service.name" value="mysql-ds"/>
</osgi:service-properties>
</osgi:service>
</beans>
<!-- Export key DataSource Pool properties into JMX for Management and Monitoring -->
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="beans">
<map>
<entry key="org.talend.DataSource:name=MySQL" value-ref="mysql-ds"/>
</map>
</property>
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.MethodNameBasedMBeanInfoAssembler">
<property name="managedMethods">
<value>
isClosed,
getDefaultAutoCommit,
setDefaultAutoCommit,
getDefaultTransactionIsolation,
setDefaultTransactionIsolation,
getDriverClassName,
getInitialSize,
getMaxActive,
setMaxActive,
getMaxIdle,
setMaxIdle,
getMaxOpenPreparedStatements,
setMaxOpenPreparedStatements,
getMaxWait,
setMaxWait,
getMinEvictableIdleTimeMillis,
setMinEvictableIdleTimeMillis,
getMinIdle,
getNumActive,
getNumIdle,
getNumTestsPerEvictionRun,
setNumTestsPerEvictionRun,
isPoolPreparedStatements,
setPoolPreparedStatements,
getRemoveAbandoned,
setRemoveAbandoned,
getRemoveAbandonedTimeout,
setRemoveAbandonedTimeout,
getTestOnBorrow,
setTestOnBorrow,
getTestOnReturn,
setTestOnReturn,
getTestWhileIdle,
setTestWhileIdle,
getTimeBetweenEvictionRunsMillis,
setTimeBetweenEvictionRunsMillis,
getUrl,
getValidationQuery,
setValidationQuery,
getValidationQueryTimeout,
setValidationQueryTimeout
</value>
</property>
</bean>
</property>
</bean>