After a 211 college graduate worked for five years, he was confused by more than 70 interview questions from Tencent (Java Senior Development Post)!

background

It's been five years since 211 graduated. I did the test for two or three months and it was not very suitable. Later, I chose to engage in back-end development, which was pretty good. Now that I have entered the early approval of the autumn recruits, I wanted to go to Dachang to try the water, so I went to Tencent, and I was stupid as a whole, and expressed doubts about life... I can ask so much without thinking about it. Crazy bombing, more than 70 questions in a series, can't stop. I feel that I will never forget this interview experience in my entire life. Let me show you my interview process. I think you will also feel the same.

 

My interview process (after 70mins)

1. Brief introduction of personal resume

2. Brief description of the project

  • Mainly highlight the difficult points, I bb a bunch of business logic results and others are not interested

3. SpringAOP implementation

  • JDK dynamic proxy: implements the Invocationhandler interface, which is essentially a new Proxy object that inherits Interface on all classes, and then invokes it through method.invoke
  • CGLib dynamic proxy: dynamically generate subclasses in memory to proxy the original object, and cannot proxy final classes and methods
  • Common restriction: cannot proxy to the nested method referenced by this in the current class

4. What kind of AOP is used?

  • JDK dynamic proxy used by default

5. Performance comparison of JDK dynamic proxy and CGLib dynamic proxy

  • The reflection of JDK will have more reflection call overhead (method permission verification, call overhead, etc.)
  • CGLib needs to create new objects. There will be more overhead in creating new objects, that is, initialization

6. Have you used Java's thread pool? Tell me about the specific parameters

Java's thread pool is a three-level storage structure. The threads are first put into the core thread pool, and then put into the cache queue when it is full. Finally, if the cache queue is also full, new threads will be expanded. So the parameters are:

  • Number of core threads
  • Cache queue type
  • Maximum number of threads
  • Thread active time
  • Thread factory methods (write logs, rename threads, etc.)

7. The difference between Execute and Submit of thread pool

  • Execute executes runnable, Submit can execute Future, we generally use countDownLatch+Future to get all thread results

8. Continue to ask, is there any other difference?

  • I don’t know, the follow-up check found the difference is as follows
  • Execute will throw an exception directly at runtime, and will throw an exception when Future.get is called after Submit

9. How does the thread pool ensure that there is no contention when the current thread acquires the workers in the pool?

  • Is the volatile state flag the worker used?

10. The characteristics of volatile

  • To ensure memory visibility by prohibiting instruction reordering, it is actually implemented using memory barriers

11. How many kinds of memory barriers are there?

I couldn't remember it at the time, so I looked back and looked as follows:

  • LoadLoad barrier: For such statements Load1; LoadLoad; Load2, before the data to be read by Load2 and subsequent read operations are accessed, it is guaranteed that the data to be read by Load1 has been read.
  • StoreStore barrier: For such statements Store1; StoreStore; Store2, before Store2 and subsequent write operations are executed, it is ensured that the write operations of Store1 are visible to other processors.
  • LoadStore barrier: For such statements Load1; LoadStore; Store2, before Store2 and subsequent write operations are flushed out, it is guaranteed that the data to be read by Load1 has been read.
  • StoreLoad barrier: For such statements Store1; StoreLoad; Load2, before Load2 and all subsequent read operations are executed, it is ensured that Store1 writes are visible to all processors. Its overhead is the largest of the four barriers. In most processor implementations, this barrier is a universal barrier, serving the functions of the other three memory barriers.

12. In addition to using memory barriers in volatile, where else does Java use memory barriers?

  • I really don’t know this. If you know, please give pointers in the comment area.

13. You mentioned CountDownLatch before, do you know its internal implementation?

  • Know that the AQS used allows all waiting threads to pass through when state=0

14. Briefly talk about AQS

AQS core design:

  • The state value of a volatile int state, using volatile to ensure thread visibility, and using int to provide reentrant multi-resource capabilities
  • Two-way queue, the first node is the execution node, it can be judged whether it is ShareLock or ExclusiveLock according to the Node information of the execution node, and an execution thread will be associated to provide reentrant judgment
  • When locking, if it is a fair lock, try to CAS load the queue, if it is an unfair lock, it will directly enter the queue
  • When unlocking, directly wake up the first wait node of the successor

15. How does AQS respond to interrupts after locking?

  • It’s too detailed. I didn’t read it so deeply before reviewing the source code.

16. OK, ask something else, what is the realization of AQS?

  • Used ReentranceLock, CountDownLatch

17, talk about realization

  • ReentranceLock rushes in by judging whether the threads are the same
  • CountDownLatch allows all awaits to pass when the state is 0

18. Have you heard of ReadWriteLock? You mentioned that there is only one State in AQS. How do you use one State to support two states for reading and writing?

  • A state is an Int, which can be divided into high bits for Read and low bits for Write, which can be used as a String

19. Int a few bytes

  • I actually answered 32, it should be 32 bits, 8 bits per byte, a total of 4 bytes

20. Have you ever used cache?

  • No, but distributed locks with redis

21. How do you talk about distributed locks?

  • Distributed lock is also a lock, which needs to meet several characteristics, 1 can be reentrant 2 can identify the identity of the lock to prevent ABA problems 3 consider whether to renew the contract
  • The key is the unique code of the business resource of the lock that needs to be added, and the value is the uuid of the current thread. The uuid is the jedis used when locking in threadLocal. First set an expiration time, then use ex. If there is no key, add a new one. key, if it already exists, it will fail directly
  • The Alibaba Cloud Enterprise Edition CAD (compareAndDelete) used for unlocking, atomically compares and unlocks, and is essentially a similar transaction operation performed through lua scripts

22. In addition to redis, what else can do distributed locks?

  • Mysql、zookeeper等

23. If you let you use Mysql as a distributed lock, what do you do?

  • Create a new table, the primary key is the lock key that needs to be locked, col1 is the thread uuid, and col2 is the ttl time
  • When locking, select the record of the current key in a transaction, if it exists, judge the ttl, if it does not exist, it can be inserted directly
  • Just delete the record when unlocking
  • Start a timed task to traverse the table, clear the expired key to prevent unlimited expansion

24. Does zookeeper understand?

  • A little bit, not deep

25. Let's continue to talk about Redis. What data structure does Redis have?

  • List,Hash,Set,Zset,List

26. How is Zset implemented?

  • Jump table + map implementation

27. What is a skip table?

  • The conventional linked list has only one next node, and the jump list holds multiple pointers to other linked lists, which can be searched in leaps and bounds. The time complexity is logn

28. What if I want to find a node with a score of A?

  • First find the corresponding node ranking in the map, and then search in the skiplist according to the ranking

29. How is zrange implemented?

  • This shouldn't be expected, I checked it as follows: ZRANGE key start stop [WITHSCORES], zrange is to return the members of the ordered set key in the specified interval, and the bottom layer of the elements in the jump table is ordered ( The above layers are the index of the jump table), sorted by score, we only need to find the element represented by start, and then traverse forward or backward M times to pull out all the data, and find the element represented by start, which is actually The time complexity of finding an element in the jump table. Each node in the jump table will save the span of each layer to the next node. In the search process, the current ranking can be obtained according to the span sum, so the search process is an O(log(N) process, plus traversing M elements , Is O(log(N)+M), so redis zrange will not have more serious performance problems like mysql offset.

30, Redis persistence

  • RDB: Snapshot storage, you can choose whether to block, use scenarios in database online and offline, primary and backup replication, etc.
  • AOF: Similar to binlog, each of them is a write event, which is a priority read strategy and supports multi-strategy write (strong synchronization, flushing according to time, handing over to the operating system to decide flushing, etc.). AOF is to prevent files Expansion also supports rewriting

31. Will the main thread be blocked when AOF is rewritten?

  • No, there is no need for this. After rewriting a sub-thread, just brush the buffer in the hand.

32. How to do it when loading

  • A local client directly reads the AOF replay commands

33. What are the multi-machine deployment solutions for Redis?

  • The classic master-backup synchronization, initialize the backup database through RDB and then execute the command to propagate Sentinel, which is actually a disaster recovery mechanism cluster, cluster deployment, using multiple machines to occupy slots to provide cluster services

34. In the active/standby environment, if a standby database is broken in the middle, how to perform synchronization when it is online again?

  • The master and backup each maintain a written Offset, and after comparing the differences, read the missing commands in the buffer and synchronize them

35. If the offset of the standby database is too backward and is no longer in the buffer?

  • Direct RDB resynchronization uses AOF to find the statement corresponding to the offset (this is my guess)

36. How does cluster failover?

  • I don’t know, it’s estimated that an objective offline is detected and paxos chooses the master

37. Does Mysql know what locks are there?

  • Type classification: shared lock (S), exclusive lock (X), intention lock (mutually exclusive with table lock)
  • Granularity classification: row lock, table lock

38. How is the row lock implemented?

  • I don’t know, it’s a bit of a breakdown at this time, why so many don’t know nnd

39, talk about the transaction isolation level

  • RU、RC、RR、Serializable

40. Which isolation level are you using?

  • mysql defaults to RR, we changed it to RC

41. Will phantom reading problems occur under the default isolation level?

  • Yes, this is one of the classic problems of RR

42. Describe the phantom reading

  • In T1, Select * From table where id = 1; if the record does not exist, the record with insert id = 1 is entered, but after the selection is completed, the T2 transaction inserts the record with id=1, and the subsequent insert execution fails, essentially It is said that the current snapshot does not support the execution of subsequent dml statements

43. Do you understand the MVCC mechanism?

  • Understand that the data isolation mechanism supported by undolog is mainly to provide higher concurrency

44, talk about the principle

  • There are two hidden rows in each row of record, one is the current transaction id, and the other is the pointer to the undolog. The mvcc mechanism runs
  • Under the two isolation levels of rr and rc, each time a ReadView is generated, the current active transaction ID is maintained in the list. If the ID of the accessed Record is smaller than the ID of the smallest active transaction, it means that it has been submitted before. It can be read directly. If it is larger than the maximum transaction ID, it proves that the transaction was not committed during this snapshot. You need to find the corresponding historical version according to the undolog. If it is between the maximum and minimum, then if it is an active transaction, find Historical version, if not read directly
  • At the RC level, each Select generates a new ReadView, so you can see the submission of different things
  • At the RR level, ReadView is only generated at the first Select, so phantom reads will occur, because the results of snapshot reads and real reads are inconsistent

45. How to deal with slow SQL?

  • Slow sql log first analyze whether the index written is wrong or the offset is too large, and then look at expain

46. ​​Which cols do you care about explain?

  • key: the index actually used
  • possible_key: possible index
  • rows: the number of scanned rows, the bigger the more it will collapse
  • filter: the proportion of filtered data, this col can verify the validity of the index
  • extra: Include whether to use index, whether to sort is filesort, etc.

47. Do you understand https?

  • The client sends a random number to the server
  • Server sends certificate + random number back
  • The client dismantles the certificate and finds a third party to verify the validity of the certificate and remove the public key
  • The client uses the public key to encrypt the third random number and sends it to the server
  • Server private key decryption

48. How do you deal with the 100% CPU of the online machine?

  • In the era of containerization, you must check if the st is too high, and there is a possibility of oversold
  • If not, then top will see which process has the problem, and then see which thread of this process eats the cpu
  • jstack directly dumps the thread and then finds the corresponding problematic thread to analyze
  • There may also be frequent GC problems caused by memory leaks. You can pull GClog and dump the heap in jmap to see.

49. What parameters do you generally adjust for online JVM?

  • XMX&XMS fixed to prevent memory jitter
  • Heap space adjustment: Young generation Age adjustment, young generation eden:s0:s1 ratio adjustment
  • Collector adjustment: lower the number of CMS pre-cleaning before the big promotion, and raise the cleaning threshold of CMS

50、Rhetorical

  • What team?
  • What business do you do?

Self-reflection

 

Although this time I went with the mentality of testing the waters, this series of 50 questions was really a bit dumbfounded, and I also found many loopholes in my own, as follows:

  • My resume is too long to be grasped by the interviewer
  • The technology stack used by the project is not reflected
  • The important and difficult points of related projects are not very clear, such as distributed locks, multi-tenant sub-databases and tables, middleware isolation schemes, performance troubleshooting, etc.
  • In fact, all kinds of technology stacks are still in the use layer, without digging deeply
  • The speed of speaking is too fast. The 70-minute interview has answered 50 questions large and small. I feel slowed down enough for me to answer two rounds

Finally summarize personal income (for your reference and study)

After this time, I reflected on it for a long time, and found that I really had many shortcomings and loopholes, so I have been planning my own learning route recently. Whether you are reviewing for the interview or studying by yourself, I believe what I said is still It's kind of useful.

1.1 First of all, the first one should sort out the knowledge outline of the entire system

Knowledge outline of the whole system

I divide the entire system into 5 topics: concurrent programming, performance tuning, Spring family bucket, cache database, distributed & microservices

1.2 Secondly, according to the above classification, study according to the outline (finally look at the interview topic)

For each topic, collect the corresponding interview study notes, such as the ones I collected below (if you are interested in this knowledge system outline I collected and the interview + study notes corresponding to each topic below, the editor can share it with You study together

Free access to article information: one-click triple + comment, then add my VX (tkzl6666) to receive it for free.

1. Concurrent programming (handwritten notes: concurrent programming+concurrent programming_principle+concurrent programming_application+concurrent programming_mode)

  • Concurrent programming

 

Concurrent programming

  • Concurrent programming_principle

 

Concurrent programming_principle

  • Concurrent programming_application

 

Concurrent programming_application

  • Concurrent programming_mode

 

Concurrent programming_mode

  1. Performance tuning (Java performance tuning actual combat: Java programming performance tuning + multi-threaded performance tuning + JVM performance monitoring and tuning + design pattern tuning + database performance tuning + actual combat exercise )

Performance tuning

  1. Spring Family Bucket (Focus on this part, I put Spring, MVC, Cloud, and Boot together)
  • Hand-drawn mind maps (to help sort out the knowledge points, I won’t take screenshots one by one)

Spring's hand-drawn mind maps

  • Advanced study notes

Spring family bucket advanced learning notes

  1. Cache database (mainly MySQL+Redis+MongDB)

MySQL+Redis+MongDB

  1. Distributed & microservices (compiled notes are as follows)

After graduating from 985 and working for a year, Tencent tested the water and asked 50 questions in a row, and instantly expressed doubts about life.

Distributed & Microservice

1.3 Finally, look at the interview topic

I started from basic-intermediate-advanced step by step, step by step, these interview questions are all sorted and sorted, and I [learn] privately to share with you (with answer analysis).

  • For example, the basic part:

Basic part

  • Intermediate part:

Intermediate part

  • Advanced part (message queue + Redis cache + sub-database sub-table + read-write separation + distributed system + high availability + microservice architecture)

Advanced part

The above is the planning of all my learning routes. Starting from the overall knowledge system, I sort out all the knowledge. If there are loopholes, I will check my relevant handwritten notes to consolidate them. Finally, I will go to the interview and brush the questions, and try to fill in the vacancies. There are no longer so many ignorance and knowledge gaps in this interview.

Having said that, whether it is the outline of the knowledge system, or the notes related to concurrent programming, performance tuning, Spring family bucket, cache database, distributed & microservices, etc., if you want to learn or review it, you can go straight Just come to the editor to share .

Free access to article information: one-click triple + comment, then add my VX (tkzl6666) to receive it for free.

Guess you like

Origin blog.csdn.net/JavaBUGa/article/details/112138330