We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
timer.schedule(new TimerTask() { public void run() { synchronized (payment.getPayId().intern()) { // 使用2分钟之前的Payment到数据库中查出当前的Payment Payment currentPayment = paymentRepository.findById(payment.getId()).orElseThrow(() -> new EntityNotFoundException(payment.getId().toString())); if (currentPayment.getPayState() == Payment.State.WAITING) { log.info("支付单{}当前状态为:WAITING,转变为:TIMEOUT", payment.getId()); accomplishSettlement(Payment.State.TIMEOUT, payment.getPayId()); } } } }, payment.getExpires());
1.先findById,2.再判断状态,3,再执行accomplishSettlement 如果产生并发可能产生在accomplishSettlement之前payment已经被支付了,是否可能产生业务问题。
The text was updated successfully, but these errors were encountered:
synchronized (payment.getPayId().intern()) 对payId加锁之后,findById得到的数据是数据库中最新的数据,不会存在findById之后被其他线程修改payment状态的情况
Sorry, something went wrong.
No branches or pull requests
timer.schedule(new TimerTask() { public void run() { synchronized (payment.getPayId().intern()) { // 使用2分钟之前的Payment到数据库中查出当前的Payment Payment currentPayment = paymentRepository.findById(payment.getId()).orElseThrow(() -> new EntityNotFoundException(payment.getId().toString())); if (currentPayment.getPayState() == Payment.State.WAITING) { log.info("支付单{}当前状态为:WAITING,转变为:TIMEOUT", payment.getId()); accomplishSettlement(Payment.State.TIMEOUT, payment.getPayId()); } } } }, payment.getExpires());
1.先findById,2.再判断状态,3,再执行accomplishSettlement
如果产生并发可能产生在accomplishSettlement之前payment已经被支付了,是否可能产生业务问题。
The text was updated successfully, but these errors were encountered: