Of course, I want to change a platform, change the direction, want to know why to job-hopping, if really want to jump, want to get an ideal offer, in addition to luck, basic skills should be enough solid, hope the following interview experience can give you to provide some help.
Project experience
The interviewer will let you introduce yourself in the first place, mainly to let you introduce some of the projects you have done, to see how well you know about these projects, because many of the items written on the resume are not all from start to finish, some just participate in and implement some of the modules, or take care of other people's projects, So you have to be able to understand the ins and outs of the project that you have written on your resume and what you say in the interview process, because the interviewer will definitely follow the description of your project, the principle of implementation in the project, or why you should ask questions about it, so that this situation will only greatly reduce the interview score.
Scene dialog:
Interviewer: (Take your CV) and tell me about the project you've been doing recently.
Me: &......%¥#*&¥@%¥! , said a chase (do not know how much the interviewer listens to, the interviewer will pick him will ask questions)
Interviewer: You said this project used Netty, can you tell me about Netty's threading model?
Me: (Fortunately I have seen the source of Netty) Netty through the reactor model based multiplexer to receive and process user requests (can speak a little more), the internal implementation of two thread pool, boss thread pool and work thread pool, One of the boss thread pool threads is responsible for handling the requested accept event, and when receiving the request of the Accept event, the corresponding socket is encapsulated in a niosocketchannel and handed to the work thread pool, The work thread pool is responsible for requesting the Read and write events (by dictating the process of drawing, the execution of the request is probably described, the time is limited, it is impossible to finish all the details, pick the key, pick the memory of the profound talk)
Interviewer: Well, the understanding is quite deep ... Do you have any difficulty in doing this project, or do you feel challenged?
Me: (At this time the interviewer wants you to make your own question, so be sure to answer, do not show you this project, if the problem is not prepared, only temporary play, of course, I belong to the temporary play) think about it a little bit, because I did encounter this problem, when doing this project, But familiar with the Netty, the request business logic in the work thread pool threads to handle, when the pressure test, found that the QPS is always on the go, and later saw the source after the discovery, because the business logic processing time-consuming, completely occupied the work thread pool resources, Causes the new request to remain in the waiting state.
Interviewer: How did that finally work out?
Me: Finally, wrap the logic of the processing business into a task that is committed to a new business thread pool and execute the requested write event by the work thread pool after execution.
Interviewer: OK, do you know that selector in NiO might trigger a bug?
Me: Well, yes, Selector's Select method, because the underlying epoll function may be idling, leading to cpu100%.
Interviewer: How do you solve the problem?
Me: This problem has been solved in Netty, through &^%&$^ (put the Netty solution to say it again)
Interviewer: Well, right, do you have a set of indicators for yourself in this project?
I: Yes, &&, ...... ¥¥##@, the indicators of their own project, how to conduct AB experiment, how to iterate the optimization index
Interviewer: Well, well, the problem with the project is here first, so let's examine the fundamentals of Java.
As above is just a project I do, of course, specific project analysis, not every interviewer asked the point is the same, if the interviewer does not understand Netty, nature will pick other questions to ask questions, but you can also try to put the problem to their familiar direction to rely on.
Interview knowledge point 1, thread pool
Thread pool Implementation principle, this knowledge point is really important, almost every interview will be asked, the general question Way has the following several:
1, "The realization principle of the 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"
Scene dialog:
Interviewer: How does the thread pool work at ordinary times?
Me: Well, I use it in my * project.
Interviewer: Well, you talk about the implementation principle of the thread pool
Me: (Fortunately I have read the source code before, but the time is a little vague), can give me a pen and paper, I draw analysis to you see,&&¥& assume that the initialization of a thread pool, the number of core threads is 5, the maximum number of threads is [email protected]@@
Interviewer: Well, OK, you go on ...
I: Draw a square on the paper, this represents a thread pool, when initialized, there is no thread
Interviewer: Well, OK, you go on ...
Me: I drew a slender rectangle, which represents a blocking queue, and in the beginning there was no task.
Interviewer: Well, OK, you go on ...
Me: When I come to a task, I draw a small circle in the square, representing the initialization of a thread, if another task, then draw a circle, indicating that another thread was initialized, after 5 consecutive circles, if the 6th task came over ...
Interviewer: Well, OK, you go on ...
Me: This will put the 6th task in the blocking queue.
Interviewer: Well, what then?
Me: There are not 5 threads in the thread pool now, and if one of the threads is idle, the 6th task will be fetched from the blocking queue for execution.
Interviewer: Well, right, what if the task is going to be faster than the speed of consumption?
Me: If 5 threads in the thread pool are in the running state, then the task is saved in the blocking queue first
Interviewer: What if the queue is full?
Me: If the queue is full, we are not setting the maximum number of threads is 10, and there are only 5 threads in the thread pool, a new thread is created to perform the task that cannot be saved to the blocking queue, and then I draw 5 circles in the square.
Interviewer: What if the number of threads in the thread pool reaches 10 and the blocking queue is full?
Me: This situation through the custom reject function to deal with the task here, Shu a mouthful, thought to have finished ...
Interviewer: OK, so what happens to the threads in the thread pool if the tasks in the blocking queue are executed after a period of time?
I:... This thread, which seems to exceed the core thread count, will automatically be recycled in a free period of time ... Because a little do not remember this logic, the answer is a bit virtual ...
Interviewer: OK, so what happens in this scenario?
Me: (sometimes really stupid, a lot of things know, but in the interview when a nervous, all forget) this ... That one... I don't think I've ever met a situation like this.
Interviewer: Well, well, when you get back, think about it.
I:........
I forgot the seconds to kill the scene.
Thread Pool Analysis Articles:
Deep analysis of the implementation principle of Java thread pool
2, the implementation of the lock
In the interview about the lock process, the general main asked synchronized and reentrantlock the implementation of the principle, more people will ask read and write locks.
Scene dialog:
Interviewer: Do you know what locks are in Java?
Me: Like synchronized and reentrantlock ... Read and write locks are not much, there is no research (I am afraid of being asked to read and write locks, because have not seen)
Interviewer: Well, first you talk about the principle of synchronized.
Me: Well, synchronized is a kind of lock implemented by the JVM, where the acquisition and release of Locks are monitorenter and monitorexit instructions, which are divided into a biased lock, a lightweight lock, and a heavy lock on the implementation. Where the bias lock in 1.6 is turned on by default, lightweight lock in the case of multi-threaded competition will be inflated into a heavyweight lock, the data about the lock is stored in the object header ... &&@@#, (well, say a lot, the interviewer didn't interrupt me)
Interviewer: Oh, well, the understanding is quite thorough, then you talk about the realization of reentrantlock ...
Me: Reentrantlock is based on the AQS implementation
Interviewer: What is Aqs?
Me: In Aqs, a state variable is saved, the value of the variable is modified by the CAs, the successful thread means that the lock is obtained, no modification succeeds, or the status state is found to be locking state, the thread is encapsulated by a waiter object, added to the wait queue, and hangs up waiting to be awakened &&&$$ (again said a bunch)
Interviewer: Can you tell me about the principles of CAS implementation?
Me: CAS is achieved through the Compareandswap method of unsafe classes (a smile in the heart)
Interviewer: Oh, well, do you know the meaning of the parameter of this method?
Me: (This is forcing me ah ...) Hard to recall, because I've really seen it. This method looks a bit long ago, the first parameter is the object to be modified, the second parameter is the offset of the object to modify the variable, the third parameter is the value before the modification, the fourth parameter is the expected modified value ... This all remembers, but the interviewer still seems unwilling to let me go ... )
Interviewer: Well, yes, do you know how the OS level is implemented?
Me: (I go to your uncle ...) I just remember that there is a CMP at the beginning of the instruction, specifically I forgot X86 ...
Interviewer: Well, well, do you know what's the disadvantage of CAS directive?
Me: Oh, the disadvantage of CAS is that there is an ABA problem
Interviewer: What do you say?
Me: is a variable V, if the variable V was first read a, and when the assignment is ready to check that it is still a, it can be explained that its value has not been modified by other threads? If during this period its value has been changed to B and then back to a, the CAS operation will mistakenly assume that it has never been modified.
Interviewer: How to solve it?
Me: (There is no end to the AH ...) My heart is broken. In this case, the Java and contract package provides a tagged atomic reference class "Atomicstampedreference", which can be controlled by the version of the variable value to ensure the correctness of the CAs.
Interviewer: Well, well, this is the end of the question, and we'll see what else
Me: ... can I have a drink of saliva?
The article about lock analysis, hope to be useful to you:
In layman's Java synchronizer Aqs
CAs in Java
In layman synchronized
In layman Reentrantlock
Unsafe in Java
Java Volatile Keyword FAQ
In-depth analysis of object.wait/notify implementation mechanisms
In-depth analysis of synchronized JVM implementations
3, Concurrenthashmap
When examining the data structure, the interviewer will start by asking hashmap the implementation principle, when you say HashMap is not thread-safe, you will let yourself lead concurrenthashmap, and then you may start the following dialogue.
Scene dialog:
Interviewer: Talk about the principle of CONCURRENTHASHMAP implementation
Me: @#¥@@ 基于 based on the%%¥#@#¥ of the segmented lock, but after 1.8 it changes the implementation mode.
Interviewer: 1.8 What's the way
Me: The implementation of the 1.8 principle of a pass, which refers to the red and black trees ...
Interviewer: Can you tell me the concept of the red and black tree?
Me: The red-black tree is a binary tree, and it is balanced ... %...... ¥ ...,
Interviewer: Can you tell me about the red and black trees?
Me: Stop, don't ask, red black tree I only know that he is two fork tree, more than the other tree properties, the other I do not know
Interviewer: OK, let's change, do you know how the size method is implemented?
Me: Size method? Do you want to get the number of elements in the map?
Interviewer: Right ....
Me: I remember it seems that the size method returned is inaccurate, and usually does not use this method ...
Interviewer: If you think the return value of the size method is inaccurate, what do you think should be done if you let yourself do it?
Me: ... @#¥@@. Two eyes, one black.
Me: Wait, let me think .... You should be able to record with the Atomicinteger variable ... Well, right, every time you insert or delete, manipulate this variable, I'm proud of a smile ...
Interviewer: Oh, well, what if I think this atomicinteger variable has a bad performance and can be optimized again?
Me: Crazy face ... (The Volitile variable was forgotten) ... It seems to be gone, I can't think of it ...
Interviewer: Oh, then look back at the source bar, the JDK has been implemented ...
Me: Oh, yes ....
Interviewer: That's the end of today's interview, we'll let you in later.
I:..................
About Concurrenthashmap, I have also written a lot of analytical articles, I hope to be useful to you:
Concurrenthashmap (1.8)
Talk about the different implementations of ConcurrentHashMap1.7 and 1.8
Analysis of Concurrenthashmap red and black tree
In-depth analysis of ConcurrentHashMap1.8 expansion implementation
Java interview should be prepared for the Knowledge Point series one