亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

架構師課學習筆記-第三周知識點

標簽:
Java

复杂订单状态设计

复杂订单状态设计

表设计注意事项

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

超卖问题及其解决

问题产生

高并发下修改共享资源

解决

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<MerchantOrderVO> httpEntity = new HttpEntity<>(merchantOrderVO, headers);
ResponseEntity<JSONResult> responseEntity = restTemplate.postForEntity(paymentUrl, httpEntity, JSONResult.class);
JSONResult paymentResult = responseEntity.getBody();

如何做内网穿透

对支付时序图的理解

如何通过轮询方式更新订单状态

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. 只是用实时性要求不高的情况
點擊查看更多內容
1人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消