tang-jie / NettyRPC

NettyRPC is high performance java rpc server base on Netty,using kryo,hessian,protostuff support message serialization.
Other
1.27k stars 506 forks source link

使用spring原生事务的问题 #9

Open qianzhiheilv opened 7 years ago

qianzhiheilv commented 7 years ago

当想整个远程服务使用spring原生事务的时候

@Service
public class PersonManageImpl implements PersonManage {

    @Transactional
    public int save(Person p) {
        //your business logic code here!
        System.out.println("person data[" + p + "] has save!");
        return 0;
    }
}

就会出现server假死的问题,在下面这个方法假死住

 private Object reflect(MessageRequest request) throws Throwable {
        String className = request.getClassName();
        Object serviceBean = handlerMap.get(className);
        String methodName = request.getMethodName();
        Object[] parameters = request.getParameters();
        return MethodUtils.invokeMethod(serviceBean, methodName, parameters);
    }
tang-jie commented 7 years ago

您好,请问下你是怎么测试的?我用github上面最新的版本,运行成功,没有出现卡死。 能不能给出代码和测试用例?附上我的测试步骤: 1、加载maven依赖:

org.springframework spring-tx 4.1.1.RELEASE

2、测试服务代码: import com.newlandframework.rpc.services.PersonManage; import com.newlandframework.rpc.services.pojo.Person; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional;

@Service public class PersonManageImpl implements PersonManage { @Transactional public int save(Person p) { //your business logic code here! System.out.println("Transactional person data[" + p + "] has save!!!"); return 0; }

public void query(Person p) {
    //your business logic code here!
    System.out.println("person data[" + p + "] has query!");
}

}

3、RPC服务端运行结果: rpc

qianzhiheilv commented 7 years ago
 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <!--驱动类-->
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <!--数据库地址,指向库 -->
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/134"/>
        <!--用户名 -->
        <property name="username" value="1111"/>
        <!--密码 -->
        <property name="password" value="1111"/>
    </bean>

    <!-- 定义JdbcTemplate的Bean -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <constructor-arg name="dataSource" ref="dataSource"/>
    </bean>

    <bean id="sqlTxManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <tx:annotation-driven transaction-manager="sqlTxManager"/>

我就加了这个配置,然后其余和你一样,加了tx,jdbc包,加了注解事务的xml,然后测试的

tang-jie commented 7 years ago

这个应该和NettyRPC没有太大关系。我手头没有mysql运行环境,所以测试样例以oracle来替代,参考你提供的配置。可以看这里:JDBC服务参考代码链接。oracle测试是没有问题的,你更新一下最新NettyRPC版本试一下。