Effect Lock in Java

Does anyone know the blocking effects in Java, especially on program execution speed ? if any, how will we overcome this effect? specific links are welcome.

+5
source share
5 answers

If your application is mostly single-threaded, you can see or degrade performance very little if the lock is too big.

In general, a single lock can be captured very quickly and efficiently using the java.concurrent libraries or the synchronized built-in keyword. They use methods such as Lock elision, adaptive locking and lock escalation (see Optimizing synchronization in Mustang ), which basically means that the compiler and / or library do some very smart things to optimize the use of locking.

This is especially true in situations where the lock is really not needed; the compiler optimizes it.

However, when many threads need to capture the same locks, you will eventually notice that the processor load of your cores will never reach 100% for a pure computing problem. Essentially, something is not as fast as possible, and your processor is just sitting idle.

() IO lock contention, , , .

+4

Java. Java <= 1.4 . Java 5.0 , . Java 6 .

, 0,5 2,0 Java 6.

, . ( ) CAS .

/ - , , .

, , , Java. http://www.infoq.com/presentations/LMAX

+3

Java- SO.

, java.util.concurrent wait() notify() sleep() stop() .

Concurrency - , , . , , ,

+2

@pst , , , , . , , , . , java.

- getInstance() . - , () . ( ) - . , , .

+1

( ) / . Amdahl Law .

Blocking, although in practice (in Java) has a negligible overhead for a purely sequential program. As described elsewhere here, performance problems arise only if you have competition.

+1
source

All Articles