Summary of the questions of Java backend development in major companies

Source: Internet
Author: User

ThreadLocal (thread Variable Copy)

Synchronized implements memory sharing, Threadlocal maintains a local variable for each THREAD.

With space-time, It is used for data isolation between threads, providing a copy of each thread that uses the variable, each of which can independently change its own copy without conflicting with the other Thread's copy.

The Threadlocal class maintains a map that stores a copy of the variable for each thread, the key of the element in the map is the thread object, and the value is a copy of the variable for the corresponding THREAD.

Threadlocal plays a huge role in spring, and it appears in the management of the request scope of the beans, transaction management, task scheduling, AOP and other Modules.

Most of the beans in spring can be declared as singleton scopes, encapsulated with threadlocal, so stateful beans can work in multi-threading in Singleton manner.

Java Memory model:

The Java Virtual machine specification divides Java runtime data into six Types.

1. Program Counter: is a data structure that holds the memory address of a program that is currently executing normally. The multithreading of a Java Virtual machine is realized by rotating threads and allocating processor time, in order to recover to the correct location after thread switching, each thread needs a separate program counter, which is "thread private".

2.Java virtual machine stack: thread-private, same as thread life cycle, used to store local variable table, operation stack, method return Value. A local variable table has a base data type, and a reference to the Object.

3. Local method stack: similar to the virtual machine stack, but it is the native method service used for the virtual MACHINE.

4.Java heap: an area of memory that is shared by all threads, with almost all of the object instances allocating memory Here.

5. Method Area: The area shared by each thread, storing the virtual machine loaded class information, constants, static variables, compiled Code.

6. Run a constant pool: represents the constants table in each class file at run Time. Includes several constants: numeric constants at compile time, methods, or references to FIELDS.

"can you talk about when the Java GC was, what it was doing, and what it was doing?"

At what Time:

1. The new generation has an Eden area and two survivor zones, first placing objects in the Eden area, and placing them on one of the survivor areas if there is not enough space, and if they still do not fit, it will trigger a minor GC that occurs in the Cenozoic. Put the surviving object in another survivor area, then empty the memory of Eden and the previous survivor Area. In a gc, if you find objects that still don't fit, put those objects into memory in the old Age.

2. Large objects and long-lived objects go directly into the old age Zone.

3. Each time the minor GC is executed, the object to be promoted to the older age should be analyzed, and if the older objects in the old age area are now larger than the remaining size of the old age area, perform a full GC to maximize the space in the old Area.

What to Do: no search from the GC roots, and there are no resurrected objects after a token cleanup.

Do what:

Cenozoic: Replication cleanup;

Old Age: labeling-clearing and Labeling-compression algorithms;

Permanent generation: The class loader itself that holds classes in Java and loads Classes.

What are GC roots:

1. Referenced objects in the virtual machine stack

2. Object referenced by static property in method area, object referenced by constant

3. The object referenced by the JNI (that is, the generally said native METHOD) in the local method stack.

Both Synchronized and lock are reentrant locks, and the same thread enters the synchronization code again. you can use the lock that you have Acquired.

Synchronized is a pessimistic locking mechanism, an exclusive LOCK. The locks.reentrantlock, however, is to complete an operation without locking each time, assuming that there is no conflict, and retry until it succeeds because of a conflict failure.

"the content display is limited, can add the group to download, the group file will update the study material regularly, as well as practiced hand small case"
"java Technology 08 group" Group No. 156643771

Summary of the questions of Java backend development in major companies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.