In the middle of March, I received a request for my resume from the big brother of Ant Financial on the hook. At that time, I was very surprised that someone from Ant Financial found me and gave it to me without thinking.
I’m flattered. I know how far behind Ali is in my level. I didn’t have the courage to vote before, even try. This time, I took the initiative to find him. At that time, I thought, Is Ali so short of people? Or is it just to achieve some KPI, naive thinking?
What I did not expect was that I received an interview invitation email from Alibaba the next day, which said that the first interview would be held within 10 working days.
Anyway, now that the interview is here, let’s try it. It would be a great honor to meet a technology company of this level and see their real gap. My time away from the company has also covered the JVM, basic data structure algorithms, and some high-frequency Java fundamentals.
On Monday night 8:25 received a phone call from ant brother, as expected, as the legend, still at work. At that time, I was surprised that it was a telephone interview, because it was not mentioned in the email. In retrospect, it seems that the first interview was basically a telephone interview, and some of my friends also had a telephone interview on the second.
To get down to business, here’s the whole thing. The order is a little inconsistent, I sorted according to the module.
To introduce myself
Self-introduction will first introduce how old, how long graduated, do what some things, recently do what content, good at part ah and so on. Here to say, the content of self-introduction as it is, don’t be too exaggerated, the content of self-introduction is recommended that we prepare in advance, don’t say when you think of where to say.
The thread part
1, what are the implementation methods of multithreading?
We inherit the Thread class, implement the Runnable interface, and finally call the start() method to start the Thread.
There is also the difference between start() and run().
Call the start() method directly, and the thread is in a ready (runnable) state, but not actually running. Instead, we get the CPU’s time slice and execute the run() method, which contains our thread body.
We run the run() method directly, which is just a normal method call, executed in the main thread, and does not enable multithreading.
2. Describe some thread deadlocks.
This problem is almost unknown to us in ordinary projects, but I have some understanding of it. The answer is: two threads are holding their own lock, but also to hold the lock held by the other, because the other’s lock has been held by the other, causing each other to wait for the release of the lock. The answer was one-sided, and there were some types of deadlock questions that were not answered, but the interviewer said it didn’t matter.
It is recommended that you prepare this question by stating the conditions, symptoms, and solutions that cause deadlocks. During the interview, the interviewer mentioned a scenario in which we encountered deadlock problems.
You can search for the following two deadlock scenarios:
-
Three chopsticks for three people: Everyone needs two chopsticks nearby to start eating
-
Bank transfer problem: Thread A transfers money from account X to account Y, thread B transfers money from account Y to account X, and A deadlock occurs.
Have thread pools been used in the project? How does it work?
Some interfaces in our project need to assemble the data of multiple services for encapsulation and then return. Here we will use multithreading to pull data in parallel to reduce the interface response time.
The interviewer said, “OK, have you looked at the source code for the thread pool? What kind of thread pools are there?”
Source code here I hesitated, I said not familiar, Then I mentioned several types of thread pools newSingleThreadExecutor, newFixedThreadPool, newCachedThreadPool but I missed one newScheduledThreadPool.
What does a thread pool work like? What are the parameters of the underlying method?
When I was answering this question, I got stuck. I know these are all ThreadPoolExecutor calls, but I can’t remember the names, so the interviewer reminds me and says it doesn’t matter.
“Do you know what his parameters are? What do they stand for?”
I answered with the number of threads and the duration of the thread, but I didn’t say anything else. Then the interviewer says, “It’s okay.”
A sidebar: Thread pools are all implemented at the bottom through ThreadPoolExecutor.
public ThreadPoolExecutor( int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)
Copy the code
The meanings of the parameters are:
- CorePoolSize: minimum number of threads in the thread pool
- MaximumPoolSize: specifies the maximum number of threads in the thread pool. If the number exceeds the maximum number, RejectedExecutionHandler will be used
- KeepAliveTime: The maximum lifetime of a thread, beyond which it is reclaimed
- Unit: unit of the maximum thread lifetime
- WorkQueue: cache queue for asynchronous tasks to be executed
- ThreadFactory: creates a threadFactory
- Handler: Reject policy. This policy is used when the workQueue is full and the number of threads in the pool reaches maximumPoolSize to refuse to add new tasks. AbortPolicy: Discarding the current task. DiscardOldestPolicy: Discarding the oldest task. CallerRunsPolicy: Executing the task by the thread that submitted the task to the thread pool. Throw RejectedExecutionException anomalies.
My answer was so limited that the interviewer stopped and said, “It doesn’t matter.”
If you’ve got it figured out here, I think you’ll also need to understand what types of thread pools are used in what situations and what questions to look out for, and chances are the interviewer will continue to dig deeper.
Here will not give the answer, I believe you to search yourself, experience will be more profound.
MyBatis part
$and # in mybatis
Answer: both of them can be used to pass parameters, but # can be used as SQL injection, and $is used as string concatenation, there may be SQL injection problems.
There is one key point left unanswered: #{} will use a placeholder for the parameter part during preprocessing. Replace with the following SQL statement:
select * from user wherename = ? ;Copy the code
${} is simply a string concatenation, which is directly concatenated into the final SQL statement in the dynamic parsing phase:
select * from user where name = 'zhouq';
Copy the code
6. How to use $and #?
$is used when concatenating table names, and # is used when passing parameter values.
7. How to establish the relationship between MYbatis DAO interface and SQL in XML file?
Mybatis will parse these XML files first. The XML file has a namespace, which can establish relations with DAO, and then each SQL segment in XML will have an ID associated with dao interface.
The interviewer then says: “If I have two of these XML files that are related to the DAO, is that a conflict?” “And then I let myself go.
My above answer is too general, there must be a problem, I suggest you to understand the principle of Mybatis.
Mybatis is gone at this point.
The database
First of all, what database do you use most, of course, mysql.
Mysql lock mechanism?
Do you understand mysql locks? I’m just going to answer one row lock. And then the others didn’t think of, just recognize, others forget.
I suggest you to understand and understand table locks, page locks and so on.
9. Exclusive locks & Shared locks Do you understand?
I thought about this place for a while and said I didn’t know much about it. In real time, usually our small business system basically did not use these, may be useful to the place, did not care about it.
The interviewer then asked the following scenario question and offered the solution.
10. Scenario problem: When thread A processes A piece of data, such as payment deduction or status update, other threads, such as THREAD B, need to block it and cannot operate on this data, including query, until thread A finishes processing, before B can process it. A and B are generated by the same business code, not different business. To use the database lock to achieve, how to achieve?
When asked, the interviewer patiently explained the situation and then asked if I had anything on my mind. In fact, I want to examine the above database lock problem.
How to implement mysql index?
The answer was B+ trees, and the interviewer then asked if he could describe the general structure of a B+ tree. I don’t know much about this part of the content.
Cache related
It was written in my project that there was a solution using multi-level caching, and the interviewer asked the following questions about the possible use of caching.
Cache breakdown, cache penetration, cache avalanche?
13. How to solve the hotspot data failure?
These two questions, before a good understanding, but not sorted into their own things, the interview also said clouds in the fog. So I specially organized an article, long long memory.
For details, please go to: Ali side about cache penetration, cache breakdown, cache avalanche and hot data failure solutions
Delete cache first or update database first, why?
I’m talking about deleting the cache first and then updating the database. That’s wrong. There’s something very wrong here.
Consider this scenario:
If thread A deletes the cache and then updates the database, thread B comes in between the time it deletes the cache and the time it updates the database, finds that the cache is missing, reads the library, reads the old data, and then updates the database again. Only then does A write the new data to the database.
A typical problem is “double-write inconsistencies”.
Discussion on this issue: Cache update routine – Chen Hao teacher
kafka
15. What roles are included in Kafka’s architecture?
I did not know how to answer this question at first, so I said a Broker. Then the interviewer reminded me: “We usually have producers, consumption and so on.” Well, there are producers, consumers, themes and so on.
During this process, the interviewer also mentioned that we usually need to configure what to write when building, etc., according to the introduction of the official website.
There are other partitions, consumer groups, and the main one is ZK.
Here is a suggestion for you to take a good look at kafka inside these concepts, belong to the architecture of the map to draw their own. It’s hard to tell when it’s really important, but you know when he brings it up. That’s definitely not the way to do it. You say it in the interview, not the interviewer.
Kafka’s smallest unit of work?
Kafka: Kafka, kafka, Kafka, Kafka We need to use the most basic components, such as producer, consumer, theme, offset, and so on.
This is a question you’d better ask the interviewer if you come across.
17, Kafka message repeat consumption problem? How do you do idempotent?
At first the interviewer said, “Do you know the problem with repeated kafka messages? Have met.
My answer is that there will be the problem of repeated message consumption. We did idempotent processing on the consumption side of the data.
The interviewer then proceeded to ask: how is idempotence done? I said by setting the data version number, database unique index, etc.
Interviewer: “OK.”
For this question, I think it would be better if you could tell the interviewer the situation of repeated consumption, for example, the delivery was repeated, and the offset was not properly handled during consumption.
Kafka ACK mechanism? How is ACK implemented in a cluster?
Here I only answer what the ACK mechanism is, but the implementation principle is not answered.
Redis
19. What data structures are available in Redis
Most commonly used are strings, along with List, Hash, Set, and ZSet.
No more questions.
But questions like why Redis is so fast, I think you should know, other partners often encounter. What is multiplexing?
The source code
20. Have you read some source code? How about frames? JDK will do.
Then I said I looked at the source code for HashMap, and went through the put and get process in general, and what its structure looks like.
How do you tell if two objects are equal? Equals equals and equals.
I didn’t ask any more questions. By now, the whole interview process is over. He said that he would reply to me about the interview in 10 working days. The whole process lasted about 40 minutes.
I know, cool.
So just to conclude
Although the order of the above modules has changed, the questions in each chunk are in order, basically from the shallow to the deep, step by step to ask.
Things like database locks, thread pools, and cache issues are almost all in the form of a barrage until you get to the bottom of it.
Through this interview, I realized the gap. But more oriented.
A word of caution:
- Common accumulation: output or teach others is the best way to learn, the light does not practice, a few days to forget.
- Deep first, then broad: Learn in depth, rather than just using the API level, system by system understanding, then move on to other.
- Build a body of knowledge: Whether it’s blogging or mapping what you’re learning, take the pieces and organize them into your own knowledge.
- Don’t take any chances: Don’t be naked, and if you have any, look around and be prepared. Big factory interview will dig you to the deepest part, don’t feel that only recite some interview questions is OK, the question is not over. It’s almost impossible to get past last-minute cramming. If you rely on the back of the test to get in, so you good, admire.
- Once in a while, go to the interview: do not learn me, to a company for more than three years, halfway did not go out to face, go out to know, what is the need to supplement.
Some of the answers to these questions may not be comprehensive, so you need to do it yourself. Here is only the focus of the interview process and content to describe out.
I hope this article has been helpful to you, even if it’s only one point, but it’s worth it. If you don’t know something, it’s time to fill it in.
Don’t stay in your comfort zone too long or you won’t get out. Come out “mix”, sooner or later must return!
Are interested in welcome to pay attention to, we exchange learning together.