环境:
过冬
我正在开发一个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)
虽然功能是同步的.
任何建议都会有所帮助.谢谢.