栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

架构师课学习笔记-第三周知识点

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

架构师课学习笔记-第三周知识点

复杂订单状态设计

表设计注意事项

下单后,数据库中的商品信息可能变更,因此不能用外键关联,需要用快照的方式

超卖问题及其解决 问题产生

高并发下修改共享资源

解决 1 加synchronized
  • 效率低下
  • 不支持集群和分布式
2 锁数据库
  • 效率低,导致数据库性能低下
3 分布式锁 4 基于数据库的乐观锁机制 如何调用其他的rest接口

使用RestTemplate

  1. 配置
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();
    }
}

  1. 使用
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里边怎么写定时任务
  1. 入口类加@EnableScheduling以支持定时任务
  2. 写定时任务
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));
    }
}

使用定时任务关闭超期订单缺点及解决方案 缺点
  1. 存在时间差,程序不够严谨
  2. 不支持集群
  • 导致同样的任务被多次执行
  • 解决方案:只用一台机器运行定时任务
  1. 对数据库全表搜索,大大影响数据库的性能
解决方案
  1. 使用消息队列(延时队列)实现
  • RabbitMQ,RocketMQ,Kafka,ZeroMQ
定时任务适用场景总结
  1. 只适用数据量小的情况
  2. 只是用实时性要求不高的情况
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/239718.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号