Ali Baba end surface by _java

Introduce yourself much to say!

 

More than one thread what's the use? (

Play the advantages of multi-core CPU

Prevent obstruction

Easy modeling

 

2 how to detect whether a thread holding an object monitor (

Thread class provides a holdsLock (Object obj) method,

If, and only if, the object obj was being held at a monitor threads will return true,

Note that this is a static method, which means that "certain threads" refers to the current thread.

 

 3 synchronized and ReentrantLock difference (

ReentrantLock can be set to acquire the lock wait time, thus avoiding deadlock

ReentrantLock can obtain information on the various locks

 

ReentrantLock flexibility to achieve multi-channel notification

volatile keywords will (ensure visibility of the thread of memory, but can not guarantee atomicity )

 

5 What is the optimistic and pessimistic locking (optimistic lock: Just like his name, for what always keep an optimistic heart,

He believes that competition does not always happen, so do not need to always hold the lock,

Alternatively attempts to modify the comparison with the value in memory. Pessimistic locking: pessimistic about security state that competition will always happen,

When resources operation, always part of the direct locking indiscriminate)

 

6 Using java to write a program would lead to deadlock

 

7 What is the spin locks (

 

Spinlock, the thread refers to try to acquire the lock will not be blocked,

But keep trying circular fashion, this benefit is to reduce the thread context switch brings unlock,

Improve performance, the disadvantage is the cycle will consume CPU.

 

8 What is the java memory model (

Java Memory Model (JMM) defines all the variables are stored in main memory, each thread also has its own working memory.

Thread of working memory in the main memory to save a copy of a copy of the variables used in the thread, the thread all operations on the variables must be in working memory,

Not directly read and write main memory. Between different threads can not access the other variables in the working memory directly,

Variables are passed between threads requires data between their working memory and main memory simultaneously.

JMM while it acts on the data synchronization process between the working memory and the main memory. It sets out how to do and when to do data synchronization data synchronization.

 

Example 9 several implementations of single mode (

Lazy mode

Starving mode

Static inner classes

Double lock mechanism

enumerate

I wish a speedy get your favorite offer

 

A large number of books interview experience and learning materials please pay attention to micro-channel public number: AVAJ   

Reply to "offer" be acquired

365 java giant plane by what you want me there

 

 

(1)   play a multi-core CPU advantage

(2)   prevent obstruction

(3)   ease of modeling

 

Guess you like

Origin www.cnblogs.com/DoubleP/p/11324994.html