当前位置:网站首页>22-05-26 西安 面试题(01)准备
22-05-26 西安 面试题(01)准备
2022-07-03 08:36:00 【£小羽毛】
I.对象的拷贝:深拷贝和浅拷贝
一个对象中存在2种类型的属性,一种是基本数据类型,一种是实例对象的引用
浅拷贝指的是:拷贝基本数据类型的值和实例对象的引用地址,不会复制一份引用对象所指向的对象,也就是浅拷贝出来的对象,内部的引用属性在内存中指的是同一个堆中的对象。
深拷贝:拷贝基本数据类型的值和实例对象的引用地址所指向的对象,俩者都会拷贝。深拷贝出来的对象,内部的引用属性指向的和拷贝之前所指向的不再是同一个堆中的对象
II.线程死锁
锁要满足的条件
- 一个资源每次只能被一个线程使用
- 一个线程在阻塞等待某个资源的时,不释放已占有资源
- 一个线程已经获得资源,在未使用完之前,不能被强行剥夺
死锁就是在锁的基础上再加一个必要条件
4. 若干线程形成头尾相接的循环等待资源关系
开发过程中如何避免死锁呢?
注意加锁顺序,保证每个线程按照同样的顺序进行加锁
注意加锁时限,针对锁设置一个超时时间
注意死锁检查,这是一种预防机制,确保在第一时间发现死锁并进行解决
III.redis 淘汰key的算法LRU和LFU区别
LRU算法(最近最少使用的 ,recently):
淘汰很久没有被访问过的数据,以最近一次访问时间做参考
LFU算法(最不经常使用,frequently)
淘汰最近一段时间被访问次数最少的数据,以次数作为参考
绝大多数情况下我们都可以使用LRU策略,当存在大量的热点缓存数据时,LFU更好点。
IV.为什么要使用缓存
缓存用途:高性能、高并发。
高性能:假设有很多读请求,那么直接将查询出来的结果放在缓存中,后面直接读缓存就好!
高并发:缓存单机承载并发量是 mysql 单机的几十倍。缓存是走内存的,内存天然就支撑高并发。
V:如何保证缓存与数据库的数据一致性?
串行化可以保证一定不会出现不一致的情况,但是它也会导致系统的吞吐量大幅度降低。
Cache Aside Pattern
- 读的时候,先读缓存,缓存没有的话,就读数据库,然后取出数据后放入缓存,同时返回响应。
- 更新的时候,先更新数据库,然后再删除缓存。
VI 什么是 Redis 的雪崩、穿透和击穿?
缓存雪崩和穿透,是缓存最大的两个问题,要么不出现,一旦出现就是致命性的问题
缓存雪崩:缓存机器意外发生了全盘宕机。缓存挂了,此时 1 秒 5000 个请求全部落数据库,数据库必然扛不住,它会报一下警,然后就挂了
缓存穿透:数据库 id 是从 1 开始的,结果黑客发过来的请求 id 全部都是负数。这样的话,缓存中不会有,请求每次都“视缓存于无物”,直接查询数据库。这种恶意攻击场景的缓存穿透就会直接把数据库给打死。
缓存击穿:就是说某个 key 非常热点,访问非常频繁,处于集中式高并发访问的情况,当这个 key 在失效的瞬间,大量的请求就击穿了缓存,直接请求数据库,就像是在一道屏障上凿开了一个洞。
边栏推荐
- GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
- How does unity fixedupdate call at a fixed frame rate
- Jupyter remote server configuration and server startup
- Find the intersection of line segments
- Allocation exception Servlet
- Mall management system of database application technology course design
- Graphics_ Learnopongl learning notes
- [concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
- [rust notes] 05 error handling
- Unity notes 1
猜你喜欢

【Rust笔记】02-所有权
![[concurrent programming] thread foundation and sharing between threads](/img/26/60fbfe65b186867a3b1cb58d481226.jpg)
[concurrent programming] thread foundation and sharing between threads

Unity editor expansion - scrolling list

Redux - learning notes

Deep parsing JVM memory model

梯度下降法求解BP神经网络的简单Demo
![[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q](/img/76/6561a78b7f883a0e75a53e037153c3.jpg)
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q

Collection interface

Chocolate installation

Student educational administration management system of C # curriculum design
随机推荐
【云原生】微服务之Feign的介绍与使用
UE4 plug in development
Constraintlayout's constraintset dynamically modifies constraints
Development material set
VIM learning notes from introduction to silk skating
【Rust 笔记】13-迭代器(上)
Binary to decimal, decimal to binary
Student educational administration management system of C # curriculum design
Chocolate installation
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
Unity editor expansion - the framework and context of unity imgui
Kunlunbase meetup is waiting for you!
[rust notes] 13 iterator (Part 1)
Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
Swagger document configuration
Visual Studio (VS) shortcut keys
php-fpm软件的安装+openresty高速缓存搭建
Collection interface
【Rust 笔记】07-结构体
Mall management system of database application technology course design