liuyangming / ByteJTA

ByteJTA is a distributed transaction manager based on the XA/2PC mechanism. It’s compatible with the JTA specification. User guide: https://github.com/liuyangming/ByteJTA/wiki
http://www.bytesoft.org
GNU Lesser General Public License v3.0
211 stars 110 forks source link

alibaba druid 的连接池配置示例有吗? #4

Open marsal1212 opened 6 years ago

liuyangming commented 6 years ago

阿里druid对XA的支持做的不好,建议使用commons-dbcp。

marsal1212 commented 6 years ago

用LocalXADataSource包裹druidDataSource这种写法会有什么问题吗?这种配置已经跑通了列子,且事务支持正常。

        <bean id="dataSource3" class="org.bytesoft.bytejta.supports.jdbc.LocalXADataSource">
        <property name="dataSource" ref="druidDataSource" />
    </bean>

    <bean id="druidDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <!-- 基本属性 url、user、password -->

        <property name="url" value="jdbc:mysql://127.0.0.1:3306/inst01" />
        <property name="username" value="root" />
        <property name="password" value="zzz" />

        <!-- 配置初始化大小、最小、最大 -->
        <property name="initialSize" value="1" />
        <property name="minIdle" value="1" />
        <property name="maxActive" value="20" />

        <!-- 配置获取连接等待超时的时间 -->
        <property name="maxWait" value="60000" />

        <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
        <property name="timeBetweenEvictionRunsMillis" value="60000" />

        <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
        <property name="minEvictableIdleTimeMillis" value="300000" />

        <property name="validationQuery" value="SELECT 'x'" />
        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />

        <!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
        <property name="poolPreparedStatements" value="true" />
        <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />

        <!-- 配置监控统计拦截的filters -->
        <property name="filters" value="stat" />
    </bean>

    <bean id="jdbcTemplate3" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource3" />
    </bean>
liuyangming commented 6 years ago

LocalXADataSource封装的是DataSource,不是XADataSource。在一个全局事务中,ByteJTA只支持一个non-XA资源参与。 所以,如果只有一个资源参与全局事务,这样写是没问题的;如果有多个资源参与全局事务,还是需要使用XADataSource。