下单后,数据库中的商品信息可能变更,因此不能用外键关联,需要用快照的方式
超卖问题及其解决 问题产生高并发下修改共享资源
解决 1 加synchronized- 效率低下
- 不支持集群和分布式
- 效率低,导致数据库性能低下
使用RestTemplate
- 配置
package com.xiong.config;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class WebMvcConfig {
@Bean
RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
return restTemplateBuilder.build();
}
}
- 使用
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("imoocUserId", "xxx");
headers.add("password", "xxxx");
HttpEntity httpEntity = new HttpEntity<>(merchantOrderVO, headers);
ResponseEntity responseEntity = restTemplate.postForEntity(paymentUrl, httpEntity, JSONResult.class);
JSonResult paymentResult = responseEntity.getBody();
如何做内网穿透
https://natapp.cn/
对支付时序图的理解微信支付文档
支付宝支付文档
如何通过轮询方式更新订单状态 cron表达式的书写cron表达式工具网站
springboot里边怎么写定时任务- 入口类加@EnableScheduling以支持定时任务
- 写定时任务
package com.xiong.job;
import com.xiong.common.utils.DateUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class OrderJob {
@Scheduled(cron = "0/1 * * * * ?")
public void autoCloseOrder() {
System.out.println("定时任务执行中:"+ DateUtil.getCurrentDateString(DateUtil.DATETIME_PATTERN));
}
}
使用定时任务关闭超期订单缺点及解决方案
缺点
- 存在时间差,程序不够严谨
- 不支持集群
- 导致同样的任务被多次执行
- 解决方案:只用一台机器运行定时任务
- 对数据库全表搜索,大大影响数据库的性能
- 使用消息队列(延时队列)实现
- RabbitMQ,RocketMQ,Kafka,ZeroMQ
- 只适用数据量小的情况
- 只是用实时性要求不高的情况



