Configure spring data source for sleep mode and @Transactional

I am currently using DriverManagerDataSource with @Transactional annotation to manage transactions. But all transactions are very slow, probably because the data source opens and closes the connection to db every time.

Which data source should be used to accelerate the transaction?

+3
source share
2 answers

DriverManagerDataSourcenot really a connection pool and should only be used for testing. You should try BasicDataSourcefrom Apache Commons DBCP . Sort of:

<bean id="dataSource" destroy-method="close" 
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
</bean>
+4
source

. - c3p0, , chkal. Spring lazyConnectionDataSourceProxy, , , . , , - , ( ).

<bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driverClassName}" />
    <property name="jdbcUrl" value="${jdbc.url}" />
    <property name="user" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <!-- Pool properties -->
    <property name="minPoolSize" value="5" />
    <property name="initialPoolSize" value="10" />
    <property name="maxPoolSize" value="50" />
    <property name="maxStatements" value="50" />
    <property name="idleConnectionTestPeriod" value="120" />
    <property name="maxIdleTime" value="1200" />

</bean>

<bean name="lazyConnectionDataSourceProxy" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
    <property name="targetDataSource" ref="dataSource" />
</bean>
+8

Source: https://habr.com/ru/post/1775079/


All Articles