1 the concept of activity, which scenarios have activity problems?

Concept: The word activity means that something right will eventually happen. An active failure occurs when an application reaches a state where execution cannot continue.

Scenario :(1) in a single-threaded application, an infinite loop is an example; (2) In concurrent programming, locking is used to ensure thread safety, but it may cause activity problems, such as deadlocks, live locks and starvation;

2 What does system. identityHashCode do?

The identityHashCode() method is a static method in the System class that evaluates the hash value based on the object’s memory address.

For strings, the hashCode() method must return the same value as long as the strings of A and B are the same, but the System.identityHashCode() method is different in all cases.

How to solve or avoid multi-threaded deadlock?

The following four conditions are necessary for a deadlock to occur, and they must be true whenever a deadlock occurs on the system, and deadlocks cannot occur unless one of these conditions is met, so you can avoid deadlocks by breaking any one of these conditions.

  1. Mutual exclusion: a resource can only be used by one process at a time.
  2. Request and hold conditions: when a process is blocked by requesting resources, it holds on to acquired resources.
  3. Non-preemption condition: a process can only release the resources it has acquired when it is used up.
  4. Cyclic waiting condition: several processes form a head – to – end cyclic waiting resource relationship;

4 How do I check which two threads are deadlocked in Thread Dump information?

5 What is hunger lock? How did it come about? What are the problems? How to solve it?

Starvation lock: A state in which one or more threads are unable to execute because they are unable to obtain required resources for any reason.

Causes :(1) the high-priority thread consumes the CPU time of all low-priority threads; (2) a thread is permanently blocked in a state waiting to enter a synchronized block because other threads can always access the synchronized block before it;

Solutions :(1) use locks instead of synchronized blocks; (2) Fair lock;

6 What is the Function of Thread priority? When is it not necessary to prioritize?

Priority function: The priority of a thread can only ensure that the CPU transfers the execution resources to the thread with a higher priority, but it does not guarantee that the thread with a higher priority can finish execution before the thread with a lower priority.

Out of priority order: Different systems have different value ranges for thread priorities. Java defines 10 levels (1-10). When threads with different priorities correspond to the same priority segment of the operating system, they are executed out of priority order.

7 What is a live lock? How did it come about? What are the problems? How to solve it?

The concept of a live lock: a task or performer is not blocked, but the thread repeatedly performs the same operation, but each operation results in failure;

Cause: Repeated attempts, failures, attempts, and failures occur because certain conditions are not met.

Cause problems: Although this problem does not block the thread, the program cannot continue executing.

Solution: The solution to live locking is to introduce randomness on each iteration, so that the program can continue to perform other tasks due to different probabilities;