Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
qianzhiheilv opened this issue Sep 13, 2017 · 3 comments
Open

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

qianzhiheilv opened this issue Sep 13, 2017 · 3 comments
Labels

Comments

@qianzhiheilv
Copy link

当想整个远程服务使用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
Copy link
Owner

您好,请问下你是怎么测试的?我用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
Copy link
Author

 <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
Copy link
Owner

tang-jie commented Sep 26, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants