directory

    • 1. What has changed between JDk1.7 and JDk1.8 Map (bottom level)?
    • 2. ConcurrentHashMap
    • 3. What is the difference between parallelism and concurrency?
    • 4. What changes have taken place between jdk1.7 and jdk1.8 Java virtual machines?
    • 5. If you were asked to design middleware yourself, how would you do it?
    • 6. What is middleware?
    • 7. Have you used ThreadLock before? What does it do?
    • 8. What is the difference between Hashcode () and equals ()?
    • 9. When is an index set in a mysql database but cannot be used?
      • (1) Function of index:
      • Mysql > select * from user where id = 1;
      • (3) When there is an index, but it is not used?
      • (4) Under what circumstances are indexes not recommended?
    • Mysql optimization will not,mycat branch, vertical branch, horizontal branch?
    • 11. Distributed transaction solution?
      • (1) What is distributed transaction?
      • (2) Solutions to realize distributed transactions in distributed systems:
    • 12 SQL statement optimization will not, say what you know?
    • Mysql storage engine
    • 14. Red black Tree principle?

1. What has changed between JDk1.7 and JDk1.8 Map (bottom level)?

After 1.8, the data structure of hashMap has changed from simple array + linked list structure to array + linked list + red-black tree. That is, when the JVM stores the K-V of a hashMap, only the key determines the slot (index in Node[]) for each entry. In addition, the Value is attached to the corresponding slot in the form of a linked list (after 1.8, if the Value length is greater than 8, it becomes a red-black tree). However, there is no synchronization in hashmap1.7 or 1.8, which is prone to concurrency problems and even an infinite loop that leads to system unavailability. The solution is the JDK’s ConcurrentHashMap, located under java.util.concurrent, which addresses concurrency issues.

2. ConcurrentHashMap

The idea is similar to that of hashMap, but it supports concurrent operations and is much more complex

3. What is the difference between parallelism and concurrency?

Concurrency: applications execute different tasks alternately. Multi-threading: Applications execute different tasks at the same time: one is executed alternately and the other is executed simultaneously.

4. What changes have taken place between jdk1.7 and jdk1.8 Java virtual machines?

The memory portion of the JVM is the heap, stack memory, and method area.

Stack memory main purpose: execute thread method, store local temporary variables and thread method execution is needed to reference the address of the object.

The main purpose of heap memory: All object information in the JVM is stored in heap memory. Heap memory is much larger than stack memory, so the JVM always manages objects in heap memory by dividing heap memory into different functional blocks.

Common error with insufficient heap memory: OutOfMemoryError

Stack memory overflow common errors: StackOverFlowError in JDK7 and previous JDK versions, Heap memory is usually divided into three regions Nursery memory (Young generation), old generation, and Permanent Generation for VM Matedata, as shown in the following figure:

At the top is the Nursery memory, where an object is created and placed in the Nursery memory in Nuersery. If it survives for more than two Survivor, it is transferred to the Old Generation.

Permanent memory stores metadata information such as object methods and variables. Permanent memory will appear the following error: Java. Lang. OutOfMemoryError: PermGen

In JDK1.8, however, you don’t get this error. The reason for this error is that in JDK1.8, the permanent Memory for metadata has been moved from the heap to native Memory. In JDK1.8, the JVM Memory structure has been changed to the following:

In this way, permanent memory does not occupy heap memory, and permanent memory errors can be avoided by self-growth. -xx :MaxMetaspaceSize=128m Garbage collection mechanisms for dead classes and classloaders run when metadata usage reaches the set value of the “MaxMetaSpaceSize” parameter. MetaSpace monitoring: MetaSpace usage is available in the verbose GC log output for HotSpot1.8.

The reasons for updating JDK1.8 are as follows: 1. Strings exist in persistent generation, which is prone to performance problems and memory overflow. 2. It is difficult to determine the size of the class and method information, so it is difficult to determine the size of the permanent generation. If it is too small, it is easy to overflow the permanent generation, while if it is too large, it is easy to overflow the old generation. 3. Persistent generation brings unnecessary complexity to GC and low efficiency of collection 4.Oracle may merge HotSpot with JRockit

5. If you were asked to design middleware yourself, how would you do it?

I think about development in the following ways:

  1. Remote procedure call
  2. Message-oriented: use funny messaging mechanism for platform-independent data exchange, and give data communication for distributed system integration, with the following three characteristics: I) communication programs can run at different times ii) communication Morning Morning House can be one-to-one, one-to-many, many-to-one or even a mixture of the above iii) programs that put messages into a message queue pull messages out of a small drug column for communication
  3. Object request proxy: provides different forms of communication services including synchronization, queuing, subscription publishing, broadcasting, etc. Can build various frameworks such as: transaction processing monitor, distributed data access, object transaction manager OTM and so on.
  4. Transaction processing monitoring has the following functions: A) Process management, including starting server processes, assigning tasks, monitoring their execution and balancing load b) transaction management, ensuring atomicity, consistency, independence and persistence of transactions under its monitoring c) communication management, providing multiple communication mechanisms between client and server, This includes request response, session, queuing, subscription publishing, broadcast, etc

6. What is middleware?

Middleware is in the software between the operating system and the application program, when using wangwang is a group of middleware integrated together, constitute a platform (development platform + running platform), in this group of middleware must have a communication middleware, that is, middleware = platform + communication. This definition also defines the main categories of middleware that can be called only in distributed systems: remote procedure call, message-oriented middleware, object request broker, transaction processing monitoring.

7. Have you used ThreadLock before? What does it do?

ThreadLock is a local thread that provides a local variable for each thread, meaning that only the current thread layer can access it. ThreadLock is thread-safe. How it works: Assigning an object to each thread is not done by ThreadLock, but by the application level. ThreadLock acts as a container. The principle is ThreadLock’s set() and get() methods. Implementation principle:

public void set(T value) { Thread t = Thread.currentThread(); ThreadLocalMap map = getMap(t); if (map ! = null) map.set(this, value); else createMap(t, value); } public T get() { Thread t = Thread.currentThread(); ThreadLocalMap map = getMap(t); if (map ! = null) { ThreadLocalMap.Entry e = map.getEntry(this); if (e ! = null) return (T)e.value; } return setInitialValue(); } 123456789101112131415161718Copy the code

8. What is the difference between Hashcode () and equals ()?

(1) Hashcode () and equals() determine whether two objects are equal. That is, the objects are the same —-> the member variables are the same —-> The hashcode values must be the same. (3) If the hashcode values of two objects are the same, the objects may not be equal. Hashcode equals hashcode equals hashcode equals hashcode equals (4) == Compare whether two references in memory refer to the same object (i.e. the same memory space).

9. When is an index set in a mysql database but cannot be used?

(1) Function of index:

Indexing fields in database tables can greatly speed up queries.

Mysql > select * from user where id = 1;

A) — common index b) — unique index: the value of a unique index column must uniquely allow empty values. If it is a combined index, the combination of column values must be unique: CREATE UNIQUE INDEX indexName ON myTABLE (username(length)) ALTER myTABLE ADD UNIQUE [indexName] ON (username(length)) – CREATE TABLE myTABLE (ID INT NOT NULL, username VARCHAR(16) NOT NULL, UNIQUE [indexName] (username(length)) ); C) — Primary key index: a special unique index that does not allow empty values. The primary key index is usually created when the table is created: CREATE TABLE mytable( ID INT NOT NULL, username VARCHAR(16) NOT NULL, PRIMARY KEY(ID) ); D) Composite index: CREATE TABLE mytable( ID INT NOT NULL, username VARCHAR(16) NOT NULL, city VARCHAR(50) NOT NULL, age INT NOT NULL ); To further squeeze the efficiency of MySQL, consider creating composite indexes. ALTER TABLE mytable ADD INDEX name_city_age (name(10),city,age);

(3) When there is an index, but it is not used?

A) If there is an OR in a condition, it will not be used even if some of the conditions are indexed. Note: To use OR and for indexes to work, each column in the OR condition must be indexed. B) For more indexes, not the first part of the use, the index will not be used. C) select * from ‘Where’; d) select * from ‘Where’; d) select * from ‘Where’; d) select * from ‘Where’; G) Mysql expects a full table scan to be faster than an index

(4) Under what circumstances are indexes not recommended?

A) select * from a where where (IS NULL/IS NOT NULL/LIKE ‘% input %’); b) select * from a where (IS NOT NULL/LIKE ‘% input %’); D) Where (<>) does not equal (<>)

Mysql optimization will not,mycat branch, vertical branch, horizontal branch?

(1) Optimize your queries for query caching (2) EXPLAIN select queries: Explain query results will tell you how index primary keys are exploited (3) use limit1 when only one row of data is required (4) Add indexes to search fields (5) Use comparable types of cases when associating tables, And index (6) never ORDER BY RAND() (7) Avoid SELECT * (8) always set an ID for each table (9) Extract recommendations from PROCEDURE ANALYS() using ENUM instead of VARCHAR (10) In Java, use Prepared Statements (13) unbufferedquery (14) to store IP addresses as UNSIGNED INT (15) fixed table length (16) vertical branch library: Vertical partitioning is a method of dividing a table in a database into several tables by column, which can reduce the complexity of the table and the number of fields for optimization purposes. (17) Horizontal segmentation: “horizontal segmentation” is a method to turn the table in the database into several tables according to the row, which can reduce the complexity of the table and the number of fields, so as to achieve the purpose of optimization. (18) Smaller columns are faster (19) Select the right storage engine (20) use an object-relational mapper (21) Be careful with permacing (22) Split large DELETE live INSERT statements

11. Distributed transaction solution?

(1) What is distributed transaction?

A. When are distributed transactions needed? A) Partitioned transactions are required in the case of local database power failure, machine downtime, network exception, message loss, message disorder, data error, unreliable TCP, storage data loss, and other exceptions. B) For example, how to ensure data consistency when the local transaction database is powered down? Database composed of even have a file, a database file and a journal article, any database write operations first log writing, go on before the operation log files When written to disk, then the power do not completed in time, when restart the database, the database will be based on the current data prior to undo rollback live redo roll, The consistency of data is guaranteed. C) Distributed theory: When the performance of a single database is bottlenecked, it is possible to partition the database (physical partition), and then partition the database on different servers. The ACID of a single database is not suitable for this kind of pain. In this cluster environment, it is difficult to achieve the ACID of the cluster, and even the efficiency performance is significantly reduced. Importantly, it’s hard to scale new partitions. A new theory is needed to use this clustering situation: CAP theorem d) CAP theorem: proposed by Eric Brewer, professor of Distribution in Berkeley, California, which states that WEB services cannot satisfy three attributes simultaneously: a. Consistency: the client knows that a sequence of operations will take place simultaneously b. availability: Each operation must end with an expected response C. availability: The client knows that a sequence of operations will take place simultaneously b. Availability: Each operation must end with an expected response C. availability: The client knows that a sequence of operations will take place simultaneously Partition fault tolerance: Operations can be completed even if a single component becomes unavailable. Specifically, in distributed systems, a WEB should support at most two of the above attributes in any database design. Designers must choose between consistency and usability. E) BASE theory: The distributed system pursues availability, which is more important than consistency. BASE theory is used to realize high availability. The idea is: we can’t do hydroxyethyl, but each application can make the system consistent in the appropriate way according to its own business characteristics. F) Database transaction characteristics: ACID I. Atomicity II. Consistency III. Independence or isolation IV. persistence

(2) Solutions to realize distributed transactions in distributed systems:

A. Two-phase commit 2PC b. compensation transaction TCC C. local message table (asynchronous ensure) D. MQ transaction message e. Sagas transaction model

12 SQL statement optimization will not, say what you know?

(2) When using JOIN, small result sets should drive large result sets. At the same time, complex join queries should be divided into multiple queries. Otherwise, more join tables will lead to more locking and blocking. (4) do not use select * to save memory (5) use batch insert statement, save interaction (6) Limit cardinality is large, SQL > select count (id), count (id), count (id), count (id), count (id), count (id), count (id), count (id), count (id), count (id) You should use count (*) (10) instead of sorting by index (11) you should never use subqueries in From statements (12) Use more WHERE restrictions, Narrow your search (13) Use indexes wisely (14) Use Explain to view SQL performance

Mysql storage engine

MySQL storage engine type:



(2) Transaction processing: If any problem occurs in the whole process, the data can be rolled back to the original state, which is called transaction processing. That is, the transaction either succeeds or fails.

14. Red black Tree principle?

(1) Properties of red-black tree: Red-black tree is a binary search tree. A memory bit is added to each node to record the node’s color, which can be RED or BLACK, balanced by the color constraint on any simple path from root to leaf. The red-black tree ensures that the longest path is no more than twice the shortest path. The properties are as follows: i. Each node is either black or red ii. The root node is black III. If a node is red, then its two children are black and there is no continuous red node iv. For each node, a simple path from that node to its descendant leaf node contains the same number of black nodes.

Original link: blog.csdn.net/Java\_Yhua/…

Some interview questions for 2020 are summarized. The interview questions are divided into 19 modules, which are: Java Basics, Containers, Multithreading, Reflection, Object copy, JavaWeb exceptions, Networking, Design Patterns, Spring/SpringMVC, SpringBoot/SpringCloud, Hibernate, MyBatis, RabbitMQ, Kafka, Zookee Per, MySQL, Redis, JVM.

Access to information above information: concern public number: programmers with stories, access to learning materials.

Remember to click follow + comment oh ~

Author: Programmers with stories link: juejin.cn/post/691465… The copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please indicate the source.