Home

凡是过往 皆为序章

缓存穿透

请求的大量数据在缓存和数据库中都不存在,缓存永远不会生效,这些请求都会去访问数据库,导致数据库压力变大而卡死或者宕机。

发生场景

  • 数据原本存在,但由于某些原因被删除(误删除、主动清理),但前端或前置的应用程序依旧保有这些数据
  • 恶意攻击行为,利用不存在的key或者恶意尝试导致产生大量不存在的业务数据请求

解决方案

  • 对于无效访问直接拦截,比如 id 为负值的,不允许请求到达redis和数据库
  • 对空值进行缓存
  • 使用布隆过滤器
阅读全文 »

底层原理

  • ArrayList 底层是基于数组实现的,ArrayList 类是一个可以动态修改的数组,与普通数组的区别就是它是没有固定大小的限制,我们可以添加或删除元素。

  • LinkedList 底层是基于链表实现的,是一种线性表,但是并不会按线性的顺序存储数据,而是在每一个节点里存到下一个节点的地址。

正因为底层数据结构的不同,他们适用的场景不同,ArrayList 更适合随机查找LinkedList 更适合删除和添加,查询、添加、删除的时间复杂度不同。

那么LinkedList的删除和添加真的一定比ArrayList快吗?

阅读全文 »

苍穹外卖java项目笔记

实体类分类

名称 说明
Entity 实体,通常和数据库中的表对应
DTO 数据传输对象,通常用于程序中各层之间传递数据
VO 视图对象,为前端展示数据提供的对象
POJO 普通java对象,只有属性和对应的getter和setter方法
阅读全文 »

新建Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Docker 镜像构建
FROM maven:3.5-jdk-8-alpine as builder

# Copy local code to the container image.
WORKDIR /app

COPY target ./target
#COPY pom.xml .
#COPY src ./src

# Build a release artifact.
#RUN mvn package -DskipTests

# Run the web service on container startup.
CMD ["java","-jar","/app/target/user-center-0.0.1-SNAPSHOT.jar","--spring.profiles.active=prod"]
阅读全文 »

流程

  1. 将用户代码保存为文件
  2. 编译代码,得到class文件
  3. 执行代码
  4. 收集整理输出结果
  5. 文件清理
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public ExecuteCodeResponse executeCode(ExecuteCodeRequest executeCodeRequest) {
// System.setSecurityManager(new DefaultSecurityManager());
List<String> inputList = executeCodeRequest.getInputList();
String code = executeCodeRequest.getCode();
String language = executeCodeRequest.getLanguage();
// 1)把用户代码保存为文件
File userCodeFile = saveCodeToFile(code);
// 2)编译代码,得到 class 文件
ExecuteMessage compileFileExecuteMessage = compileFile(userCodeFile);
System.out.println(compileFileExecuteMessage);
// 编译错误直接返回
if (compileFileExecuteMessage.getExitValue() != 0) {
ExecuteCodeResponse compilerErrorResponse = new ExecuteCodeResponse();
compilerErrorResponse.setStatus(3);
JudgeInfo judgeInfo = new JudgeInfo();
judgeInfo.setMessage("编译错误");
compilerErrorResponse.setJudgeInfo(judgeInfo);
return compilerErrorResponse;
}
// 3)执行代码
List<ExecuteMessage> executeMessageList = runFile(userCodeFile, inputList);
// 4)收集整理输出结果
ExecuteCodeResponse outputResponse = getOutputResponse(executeMessageList);
// 5)文件清理
boolean b = clearFile(userCodeFile);
if (!b) {
log.error("删除文件失败,文件地址 = {}", userCodeFile.getAbsoluteFile());
}
return outputResponse;
}
阅读全文 »

求素数(2 3 5 7 11……)

1
2
3
4
5
6
7
8
9
10
11
bool isPrime(int n) {
if (n <= 1) {
return false;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
阅读全文 »

一、计算机网络概述

1.互联网构成

网络边缘: 位于互联网边缘与互联网相连的计算机和其他设备,如桌面计算机、移动计算机、服务器、其他智能终端设备(end systems、clients、servers)

网络核心:由互联端系统的分组交换设备和通信链路构成的网状网络
如:分组交换路由器(rooters)、链路层交换机、通信链路(光纤、铜缆、无线电、激光链路)

阅读全文 »

1.第二章

1.1 函数定义

c++中,定义函数的时候可以让最右边的连续若干个参数有缺省值,在调用函数的时候,如果不写相应位置的参数,则调用的参数就为缺省值。

*注意是右往左连续参数

1
int func(int a=1,int b,int c=2){} //不合法
阅读全文 »

2023年1月28日晚上11点,我终于完成了个人网页的搭建,但是网站的内容还是很少,后期会慢慢加上去的。以前一直想拥有一个属于自己的网站,现在终于实现了这个目标,还是非常开心的 哈哈哈😁😁😁