Cisco Foundation Group Interview (Part)

After three rounds of face-to-face, the first two rounds were broken because the recorded video was broken, so many questions were forgotten.

Round 1

  • Q: Give an example to explain why the hashmap thread is not safe
    A 1 : JDK1.8 HashMap thread is not safe is reflected in: data coverage:
    insert image description here
    the sixth line of code is to determine whether there is a hash collision, assuming that two threads A and B are performing put operations, and The insertion subscript calculated by the hash function is the same. When thread A executes the sixth line of code, it is suspended due to the exhaustion of the time slice, and thread B inserts the element at the subscript after getting the time slice, and it is completed. Normal insertion, and then thread A obtains the time slice. Since the hash collision judgment has been made before, no judgment will be made at this time, but the insertion will be performed directly. This will cause the data inserted by thread B to be overwritten by thread A. , and thus thread-unsafe.
    I compared ConcurrentHashMap in the same place, using CAS operation:
    insert image description here

  • volatile, CAS etc

  • AQS

  • Why is this piece of data stored in both mysql and elasticSearch? Can it only be stored in es?

  • How does kafka ensure the reliability of messages

  • How does kafka speed up consumption


Questions about Round 2 algorithm and data structure. For example, topK: How to find the words with the top k (k is relatively small, at most 1/4) of frequency in a document?
Later, I thought that when the memory can hold the entire document, there are two methods. The second method based on quick sorting can achieve time complexity O(N): First of
all, no matter which method is used, it is necessary to first count the documents in the document. The frequency of the word, and get an array of Entry, this part of the time is O(N). Then:
Method 1: Use a small root heap, the time complexity of this part is O(Nlogk)
Method 2: Based on quick sort, the time complexity of this part is O(N)

If the memory cannot hold the entire document, then expand based on method one.

Round 3

  • Introduce the virtual counselor project and talk about distributed locks
  • Http long connection
  • Which packet capture tools have you used under linux?
  • Do you know the MTU (Maximum Transmission Unit)
  • Through the netstat command, we can see that many tcp connections are in the TIME_WAIT state. What does this mean?
  • A parent process with a lock forks a child process. Are the locks of the two processes mutually exclusive?
  • Process and thread related issues
  • k8s network: how do pods between different nodes communicate? Namespaces? Know IPTables?
  • In terms of network, do you understand tunneling technology?
  • synchronized lock upgrade
  • How to solve the package conflict problem during Maven build

  1. Why is HashMap thread unsafe↩︎

  2. LeetcodeCn's 347. Solution of the first K high-frequency elements↩︎

Guess you like

Origin blog.csdn.net/qq_23204557/article/details/128974318