小编som*_*one的帖子

Spring同步方法NOT SYNCHRONIZED

环境:

  • apache tomcat 7
  • java 7
  • oracle 11g
  • 日食
  • apache jmeter 2.1
  • 弹簧
  • 过冬

    我正在开发一个Web应用程序,它接收来自客户端的请求,并根据要在进一步处理中使用的请求类型为它们生成序列号.为了生成唯一的序列号,我有一种从DB获取当前序列号并将其递增1然后用新序列号更新该记录的方法.

功能:

    @Transactional
public synchronized Long generateSequenseNumber(String requestType) {
     //get current sequence number for this requestType
            //increment it by one
            //update it in DB

}
Run Code Online (Sandbox Code Playgroud)

该函数工作正常,但问题是当我从压力测试工具(JMeter)调用应用程序每秒发送50个请求时,我得到以下异常:

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [
Run Code Online (Sandbox Code Playgroud)

虽然功能是同步的.

任何建议都会有所帮助.谢谢.

tomcat hibernate spring-mvc jmeter

4
推荐指数
1
解决办法
3441
查看次数

标签 统计

hibernate ×1

jmeter ×1

spring-mvc ×1

tomcat ×1