当前位置:网站首页>22-05-26 Xi'an interview question (01) preparation
22-05-26 Xi'an interview question (01) preparation
2022-07-03 08:48:00 【£ small feather】
I. Copy of object : Deep copy and light copy
An object exists 2 There are two types of properties , One is basic data type , One is the reference of instance object
Shallow copy refers to : Copy the value of the basic data type and the reference address of the instance object , It will not copy the object pointed to by a reference object , That is, the objects that are copied out , Internal reference attributes refer to objects in the same heap in memory .
Deep copy : Copy the value of the basic data type and the object pointed to by the reference address of the instance object , Both will copy . Deeply copied objects , The internal reference attribute points to an object in the same heap no longer as the object pointed to before copying
II. thread deadlock
Conditions to be satisfied by the lock
- A resource can only be used by one thread at a time
- A thread is blocking waiting for a resource , Do not release occupied resources
- A thread has obtained resources , Before use , Can't be forcibly deprived of
Deadlock is to add a necessary condition to the lock
4. A number of threads form end-to-end loops waiting for resource relationships
How to avoid deadlock in the development process ?
Pay attention to the locking sequence , Ensure that each thread locks in the same order
Pay attention to the locking time limit , Set a timeout for the lock
Pay attention to deadlock checking , It's a preventive mechanism , Ensure that deadlocks are discovered and resolved at the first time
III.redis Eliminate key The algorithm of LRU and LFU difference
LRU Algorithm ( Least recently used ,recently):
Eliminate data that has not been accessed for a long time , Take the latest visit time as a reference
LFU Algorithm ( The least used ,frequently)
Eliminate the data that has been accessed the least in recent time , Take the number of times as a reference
In most cases, we can use LRU Strategy , When there is a large amount of hotspot cache data ,LFU Better .
IV. Why use caching
cache purpose : High performance 、 High concurrency .
High performance : Suppose there are many read requests , Then directly put the results of the query in the cache , Just read the cache directly later !
High concurrency : The concurrency of a single cache is mysql Dozens of times of single machine . Cache is memory driven , Memory naturally supports high concurrency .
V: How to ensure the data consistency between cache and database ?
Serialization ensures that no inconsistencies will occur , But it will also cause the throughput of the system to be greatly reduced .
Cache Aside Pattern
- When reading , Read cache first , If there is no cache , Reading database , Then take out the data and put it into the cache , Return response at the same time .
- When it's updated , Update the database first , Then delete the cache .
VI What is? Redis The avalanche of 、 Penetration and breakdown ?
Cache avalanche and penetration , The two biggest problems in caching , Or it doesn't show up , When it does, it's fatal
Cache avalanche : The cache machine went down unexpectedly . The cache is down , here 1 second 5000 Requests all drop to database , Database can't bear it , It will call the police , And then I hung up
Cache penetration : database id It's from 1 At the beginning , As a result, the request from the hacker id All negative numbers . In this case , Not in cache , Request every time “ View cache in nothing ”, Direct query database . The cache penetration in this malicious attack scenario will directly kill the database .
Cache breakdown : That is to say, some key Very hot , Very frequent visits , Centralized high concurrent access , When this key At the moment of failure , A large number of requests break down the cache , Direct request database , It's like making a hole in a barrier .
边栏推荐
- Query XML documents with XPath
- Log4j2 vulnerability recurrence and analysis
- Introduction to hexadecimal coding
- [rust notes] 05 error handling
- Binary to decimal, decimal to binary
- 单调栈-42. 接雨水
- Creation and content of mapnode -- osgearth rendering engine series (2)
- Unity Editor Extension - event handling
- Pit & ADB wireless debugging of vivo real machine debugging
- 22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
猜你喜欢
![[concurrent programming] consistency hash](/img/5e/3d0a52caa8ca489a6e6267274bbb39.jpg)
[concurrent programming] consistency hash

Annotations simplify configuration and loading at startup

Animation_ IK overview

Constraintlayout's constraintset dynamically modifies constraints
![[concurrent programming] Table hopping and blocking queue](/img/b7/023991a00956e469af855e7a81e126.jpg)
[concurrent programming] Table hopping and blocking queue

Kunlunbase meetup is waiting for you!

Final review of Database Principles

Redis data structure

Drawing maze EasyX library with recursive backtracking method

Unity learning notes
随机推荐
MySQL containerization (1) docker installation MySQL
Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)
【Rust笔记】05-错误处理
Transmit pictures with Base64 encoding
[rust notes] 07 structure
[rust notes] 09- special types and generics
了解小程序的笔记 2022/7/3
Sending and receiving of request parameters
【Rust 笔记】11-实用特型
[public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
Dom4j遍历和更新XML
Alibaba canal actual combat
22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制
Kunlunbase meetup is waiting for you!
Redux - learning notes
XPath实现XML文档的查询
Unity editor expansion - window, sub window, menu, right-click menu (context menu)
Drawing maze EasyX library with recursive backtracking method
PHP function date (), y-m-d h:i:s in English case
Introduction to hexadecimal coding