preface

Hello, everyone. I am a little boy picking up field snails. Many knowledge points of computer programming often have similar examples in daily life. Recently, we compiled ten very vivid life examples to help you understand these computer interview essential knowledge points.

  • Public number: a boy picking up snails
  • Github address, thanks to every star

1. How to understand HTTP statelessness?

Each HTTP request is independent and unrelated, and no context information needs to be saved by default. Let’s look at an easy to understand example:

Stateful:

  • A: What’s for today?
  • B: Tilapia!
  • A: How does it taste?
  • B: Not bad. It smells good.

Stateless:

  • A: What’s for today?
  • B: Tilapia!
  • A: How does it taste?
  • B:? Ah? What? What the hell? What does it taste like?

Add cookies:

  • A: What’s for today?
  • B: Tilapia
  • A: How was the tilapia you had today?
  • B: Not bad. It smells good.

2. What is serialization? What is deserialization?

  • Serialization: The process of converting Java objects into byte sequences
  • Antisequence: The process of restoring a sequence of bytes to Java objects

As a wandering yard farmer in the big city, moving is the norm. When we move a desk, it’s too big to fit through a smaller door, so we have to take it apart and move it through, and the process of taking it apart is called serialization. The process of putting the desk back together is deserialization.

3. What is current limiting?

In our daily development, we often hear the words interface limiting, QPS, etc. So what is current limiting? In computer networks, limiting traffic is to control the rate at which a network interface sends or receives requests.

Take life as an example: some popular tourist attractions usually have a limit on the number of visitors per day and only sell a fixed number of tickets, such as 5000 tickets per day. If you arrive late during the May Day or National Day holidays, the tickets may have been sold out and you will not be able to go in. Even if you do get in at the end, the line is so long that you doubt your life.

4. Why is the TCP handshake three times? Can’t be twice? Can’t be four times?

Why are TCP handshakes three times? The most important thing for two people to get together is to love each other, that is, I love you, and I know that you love me. Let’s simulate the process of three handshakes.

Why can’t you shake hands twice?

If there are only two handshakes, the girl may not know, her “I love you too”, whether the boy received, the love relationship will not be happy.

Why can’t you shake hands four times?

Because you can’t shake hands four times? Because three times is enough, three times is enough to let both sides know: you love me, I love you. Four times is more than enough.

5. How thread pools work

If the interviewer wants us to talk about how a thread pool works, you can just talk about the following flow chart:

To illustrate thread pool execution, let me use an analogy:

  • Core threads are compared to company employees
  • Non-core threads are compared to outsourced employees
  • Blocking queues are compared to requirements pools
  • Submitting tasks is like making a request

  • When the product makes a requirement, regular employees (core threads) take the requirement first (perform the task)
  • If all the regular employees have requirements working, i.e., the core thread count is full), the product puts the requirements in the requirements pool (blocking queue) first.
  • What if the demand pool (blocking queue) is also full, but the product continues to demand? Then outsource (non-core threads) to do it.
  • If all the employees (maximum number of threads is also full) are required to do it, then the rejection policy is implemented.
  • If the outsourcer completes the requirement, it leaves the company after a keepAliveTime.

6. How does the TCP traffic window control traffic

Let’s look at a class: a scene where the teacher is lecturing and the students are taking notes. Suppose the teacher reads a passage and asks the students and children to take notes.

The first mode:

  • The teacher said,” Once upon a time, there was a woman named Ma Dongmei. She likes Charlotte, and Charlotte likes Chia.
  • The student wrote,” Once upon a time…” “Teacher, you speak too fast. I can’t follow you.”

So they switched to model two

  • The teacher said,” Since.”
  • The student writes,” from. “The student says,” Um.”
  • The teacher said,” Before.”
  • The students write,” before. “The students say,” Um.”
  • The teacher said,” I wanted to leave work early today…”

So they switched to another model, model three

  • The teacher said,” There was a man.”
  • The student writes,” Once upon a time there was a man. “The student says,” HMM.”
  • The teacher said,” Her name is Ma Dongmei.”
  • The student wrote,” Her name is Horse… The students said, “Ma what May?”
  • The teacher said,” Her name is Ma Dongmei.”
  • Students write “Her name is Ma Dong…” The students said, “Ma Dong what?”
  • The teacher, “…”
  • The student said,” Sometimes I can remember all five words when I’m good, and sometimes I can’t when I’m bad. I was wondering if you could slow down a little while I was having a bad day

So they switched to pattern four:

  • The teacher said,” There was a man.”
  • The student says,” There was a guy. “The student says,” Well, five more.”
  • The teacher said,” Her name is Ma Dongmei.”
  • The student wrote,” Her name is Ma.. “The student said,” What? Let’s do it again. Let’s do two.”
  • The teacher says,” Her name is. “The student writes,” Her name is.”
  • And the student says,” Well, three more.”
  • The teacher said,” Ma Dongmei “.
  • The students write,” Ma Dongmei “.
  • And the student says,” Well, give me 20.”
  • The teacher said,” She likes Charlotte, and Charlotte likes Chia.”
  • Students to write…

So?

  • The first mode is simple and rough, sending only hair, receiving may not keep up.
  • The second mode is stable but inefficient. Every time you send a message, you have to wait for confirmation before sending it again, which takes a long time.
  • The third mode improves efficiency by sending packets in groups, but how to determine the size of the packets?
  • The fourth mode really plays the role of flow control, when the receiver thinks the condition is good, let the sender send more each time. Let the sender send less at a time when the receiver thinks it is in bad condition (blocking).

7. Differences between BIO, NIO and AIO

  • Blocking -IO for short BIO
  • Synchronous non-blocking (NIO)
  • Asynchronous non-blocking (AIO)

A life example:

  • Xiao Ming went to tongren Shiji’s coconut chicken and waited in line for an hour before starting to eat hot pot. (BIO)
  • Xiao Hong also went to Tongren’s Four Seasons coconut Chicken. She saw that she would have to wait a long time, so she went shopping for a while. Every time she went shopping, she would run back to see if it was her turn. So she ended up shopping and eating coconut chicken. (NIO)
  • As Xiaohua, to eat coconut chicken, because he is a senior member, so the store manager said, you go to the mall to stroll, as soon as there is a place, I will call you immediately. So Xiaohua didn’t have to sit idly and wait, nor did she have to come back every few minutes to see if there was any waiting, she finally had delicious coconut chicken (AIO).

8. What deadlock?

A deadlock is a phenomenon in which two or more processes are blocked during execution, either by competing for resources or by communicating with each other, and cannot proceed without external action.

Suppose you want to drive into a village, and the road at the entrance is so narrow that only one car can pass. At this moment, another car comes to the front of you. You are all halfway there, and neither of you wants to go back.

9. Why does TCP need four waves

For example, suppose Xiao Ming and Xiao Hong are talking on the phone. The conversation is almost over:

“I have nothing more to say,” said Xiao Hong. Xiao Ming answered, “I know.” But Xiao Ming may have something to say, xiao Hong can not ask Xiao Ming to follow his rhythm to end the call, so Xiao Ming may talk about a lot, finally xiao Ming said “I finished”, Xiao Hong replied “I know”, so the call is over.

10. Differences between Select and epoll

As for SELECT and ePoll, I’m sure you’re all familiar with them. They both use IO multiplexing. Read/write events for multiple descriptors can be monitored, and once a descriptor is ready (usually when a read or write event has occurred), the event can be notified to the corresponding application to dispose of the event.

What’s the essential difference between Select and epoll?

  • When there are a large number of sockets, each select() is scheduled by traversing FD_SETSIZE sockets, regardless of which sockets are active.
  • Epoll uses the ready notification method of “events” to register a callback function for the socket. Only active FDS are available, and the related operations are automatically completed, avoiding polling and improving efficiency.

Here’s a similar example of life:

If we could turn back the clock, we would go back to college. You go to the girls ‘dorms, find your girlfriend. So you find the dorm lady, dorm lady will take you, room by room until you find your girlfriend (this is the SELECT version); Epoll version of the version, you come, you give your girlfriend’s name and dorm room number to the housekeeper, mom directly help you find your girlfriend.

The last

I am a little boy picking up field snails, thank you for reading, I hope this article is helpful to you; Interested partners can pay attention to my public number ha: a little boy picking up snails