About looking for a job

quote


Mr. Ma said that there are many reasons for employees to leave, but only two are the most real:
• Money, not given
enough • Heart, wronged

Of course , I want to change the platform, change the direction, and figure out why I want to change jobs, if I really want to If you want to change jobs and get an ideal offer, in addition to luck, the basic skills must be solid enough. I hope the following interview experience can provide you with some help.

Project experience The

interviewer will ask you to introduce yourself at the beginning, mainly to let you introduce some projects you have done and see how well you understand these projects, because many projects written on resumes are not all from scratch Participated in the end, some just participated in and implemented some of the modules, or took over to maintain other people's projects, so you must be able to understand the ins and outs of the project experience written on your resume and in the interview process. , because the interviewer will definitely ask questions about the implementation principle in the project, or why it is implemented in this way, based on your project description. At this time, you will not be dumb and don’t know how to answer. This situation will only greatly reduce the interview score.

Scenario Dialogue:
Interviewer: (holding resume) Tell me about the project you have done recently

Me : &...%¥#*&¥@%¥! , said a big pass (I don't know how much the interviewer listened to, the interviewer will pick him to ask questions)

Interviewer: You said that netty was used in this project, can you talk about the threading model of netty?

Me: (fortunately, I have seen the source code of netty) netty receives and processes user requests based on the multiplexer through the Reactor model (more if I can talk about it), and internally implements two thread pools, the boss thread pool and the work thread pool , in which the thread of the boss thread pool is responsible for processing the accept event of the request. When receiving the request of the accept event, the corresponding socket is encapsulated into a NioSocketChannel and handed over to the work thread pool, where the work thread pool is responsible for the read and write of the request. Event (by means of dictation and drawing, the execution process of the request is roughly described, time is limited, and it is impossible to finish all the details, pick the key points, and pick the memorable ones)

Interviewer: Well, I understand It's quite in-depth... So did you encounter any difficulties or challenges when working on this project?

Me: (At this time, the interviewer wants you to answer the question yourself, so you must answer it. If you don’t answer, you will not be able to highlight your project. If you haven’t prepared this question, you can only play it temporarily. Of course, I belong to Temporarily) think about it a little bit, because I did encounter this problem before. When I was working on this project, I was not familiar with netty. The business logic of the request was processed in the thread of the work thread pool, and when the pressure test was performed, It was found that qps could not always go up. Later, after reading the source code, I found that because the processing of business logic is time-consuming, it completely occupies the resources of the work thread pool, resulting in a waiting state for new requests.

Interviewer: How was it resolved in the end?

Me: Finally, encapsulate the business logic into a task and submit it to a new business thread pool for execution. After the execution, the work thread pool executes the requested write event.

Interviewer: Okay, do you know that selectors in nio may trigger bugs?

Me: Well, yes, the selector's select method, because the underlying epoll function may be idling, resulting in cpu100%.

Interviewer: So how to solve this problem?

Me: This problem has been solved in netty, through &^%&$^ (reporting netty's solution)

Interviewer: Well, by the way, do you have any indicators for yourself in this project?

Me: Yes, &&…………¥¥##@, I talked about the indicators of my project, how to conduct AB experiments, and how to iteratively optimize indicators

Interviewer : Well, okay, the problem of the project is here first, we Let's examine the basics of java.

The above is just a project that I have done. Of course, the specific project is analyzed in detail, and not every interviewer asks the same points. If the interviewer does not understand netty, he will naturally choose other questions to ask, but you can also try Rely on the problem in the direction that you are familiar with.

Interview knowledge points

1.

Thread pool The realization principle of thread pool, this knowledge point is really important, almost every interview will be asked, the general questioning methods are as follows:
1. "Tell me about the realization principle of thread pool"
2. "What is the difference between coreNum and maxNum in the thread pool?"
3. "How to set the thread pool parameters in different business scenarios"

Scenario Dialogue:
Interviewer: How much do you usually use the thread pool? Me: Well

, I used it in my *project

Interviewer : Well, you can talk about the implementation principle of the thread pool

paper

_

_ A square is drawn, which represents a thread pool. When initialized, there are no threads in it.

Interviewer : Well, okay, you continue...

Me: I drew another slender rectangle, which represents the blocking queue. At first, there were no tasks in it.

Interviewer : Well, okay, you continue...

Me: When a task came, I drew a small rectangle in the square. A circle means that a thread has been initialized. If there is another task, draw another circle to indicate that another thread has been initialized. After drawing 5 circles in a row, if the sixth task comes...

Interviewer: Well, okay, You go on...

Me: At this point, the 6th task will be put into the blocking queue..

Interviewer: Well, then what?

Me: Isn't there 5 threads in the thread pool now? If one of the threads is idle, it will get the sixth task from the blocking queue and execute it.

Interviewer: Well, yes, then if the task is generated Is it faster than consumption?

Me: If all 5 threads of the thread pool are in the running state, then the task will be stored in the blocking queue first.

Interviewer : What if the queue is full?

Me: If the queue is full, didn't we set the maximum number of threads to 10, and there are only 5 threads in the thread pool, then a new thread will be created to execute the tasks that cannot be saved to the blocking queue, and then I will draw in the square again 5 circles.

Interviewer: What if the number of threads in the thread pool reaches 10 and the blocking queue is full?

Me: In this case, I use the custom reject function to handle this task. I took a sigh of relief and thought it was over...

Interviewer: Okay, then if the task in the blocking queue is executed after a period of time, the thread pool will be executed. What will happen to the thread?

Me: ... It seems that the thread that exceeds the number of core threads will be automatically recycled in an idle period of time... Because I don't remember the logic a bit, the answer is a bit false...

Interviewer: OK, then in what scenario does this happen?

Me: (Sometimes I'm really stupid, I know a lot of things, but when I get nervous during the interview, I forget all about it) This...that...I don't seem to have encountered such a situation.

Interviewer : Well, okay, you can wait until you go back. Think about it.

I : .......

I actually forgot to kill this scene.

Thread pool analysis article: In
-depth analysis of the implementation principle of java thread pool

2. Implementation of locks

In the interview process about locks, I usually mainly ask Synchronized and ReentrantLock. The realization principle, what is more, will ask the read-write lock.

Scenario Dialogue:
Interviewer: Do you all know what locks are in Java?

Me: For example, Synchronized and ReentrantLock... I don’t use the read-write lock much, so I haven’t studied it (I’m afraid of being asked about the read-write lock, because I haven’t seen it)

Interviewer: Well, let’s talk about the implementation principle of Synchronized first.

Me: Well, Synchronized is a kind of lock implemented by the JVM. The acquisition and release of the lock are the monitorenter and monitorexit instructions respectively. The lock is divided into biased lock, lightweight lock and heavyweight lock in terms of implementation. The biased lock is in 1.6 It is enabled by default. Lightweight locks will expand into heavyweight locks in the case of multi-threaded competition. The data about locks are stored in the object header...&&@@#, (Well, I said a lot, the interviewer Didn't interrupt me)

Interviewer: Oh, um, I understand it quite well, then tell me about the implementation of ReentrantLock...

Me: ReentrantLock is implemented based on AQS

Interviewer : What is AQS?

Me: A state variable state will be saved inside AQS, and the value of the variable will be modified through CAS. The thread that successfully modifies the lock indicates that it has acquired the lock. If the modification is not successful, or the state is found to be locked, it will be encapsulated by a Waiter object. Thread, added to the waiting queue, and suspended waiting to be woken up &&&$$ (again said a bunch)

Interviewer: Can you talk about the implementation principle of CAS?

Me: CAS is implemented through the compareAndSwap method of the unsafe class (smiles proudly)

Interviewer: Oh, okay, so do you know the meaning of the parameters of this method?

Me: (This is forcing me... I try to recall, because I have really seen it) I think about it, this method has been seen for a long time, the first parameter is the object to be modified, and the second parameter It is the offset of the variable to be modified in the object, the third parameter is the value before the modification, and the fourth parameter is the expected modified value.... (I admire myself a bit after I say it, I remember this, but the interviewer seems to be Still won't let me go...)

Interviewer: Well, yes, then do you know how the operating system level is implemented?

Me: (I'll go to your uncle...) I only remember that there is a command starting with cmp in X86, I forgot the specific...

Interviewer: Well, well, do you know the shortcomings of the CAS command?

Me : Oh, the shortcomings of CAS are There are ABA problems

Interviewer : How to say it?

Me: It is a variable V. If the variable V is A when it is first read, and it is checked that it is still A when it is ready to be assigned, does that mean that its value has not been modified by other threads? If during this period its value was ever changed to B and then back to A, the CAS operation would mistake it for it was never changed.

Interviewer: How to solve it?

Me: (there is no end...my heart is broken) In response to this situation, the java concurrent package provides a marked atomic reference class "AtomicStampedReference", which can guarantee CAS by controlling the version of the variable value correctness. Interviewer : Well , okay

, this is the end of this question, let's look at

other things Synchronized in-depth explanation of Unsafe java volatile keyword in ReentrantLock java. In-depth analysis of Object.wait/notify implementation mechanism In -depth analysis of synchronized JVM implementation 3. ConcurrentHashMap Saying that HashMap is not thread-safe will lead you to elicit ConcurrentHashMap yourself, and you might start a conversation like the following. Scenario Dialogue: Interviewer: Talk about the implementation principle of ConcurrentHashMap Me : @#¥@@%%¥#@#¥ based on segmented lock, but the implementation method has changed after 1.8 Interviewer: 1.8 What method I : Implement 1.8 The principle was explained, and the red-black tree was mentioned... Interviewer: Can you explain the concept of red-black tree?


























Me: The red-black tree is a kind of binary tree, and it is balanced...%...¥....

Interviewer: I can talk about the red-black tree. . . . .

Me: Stop, don’t ask, I only know that the red-black tree is a binary tree, it has one more attribute than other trees, and I don’t know anything else.
Interviewer : Okay, then change it. You know how its size method is implemented What?

me: size method? Do you want to get the number of elements in the Map?

Interviewer: Right....

Me: I remember that the return value of the size method is inaccurate, and I don't usually use this method...

Interviewer: If you think the return value of the size method is inaccurate, then if you let you implement it yourself, you How do you think it should be done?

Me: …@#¥@@…Both eyes are black

Me : Wait, let me think…..It should be possible to record with AtomicInteger variable…Well, yes, every time you insert or delete, operate this variable, I smiled proudly...

Interviewer: Oh, yes, then if I think the performance of this variable AtomicInteger is not good, can I optimize it further?

Me: stunned face... (I forgot the volatile variable at that time)... It seems that there is no more, I can't think of it...

Interviewer: Oh, look at the source code later, it has been implemented in jdk...

Me: Oh , is it....

Interviewer: That's the end of today's interview, we will inform you later.

Me: ………………

About ConcurrentHashMap, I have also written a lot of analysis articles, I hope it will be useful to everyone:


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326395538&siteId=291194637