On Lock and Synchronized

"A" two differences (General said it first):

       1.lock is an interface, synchronized keyword in Java, the synchronized is built-in Java language implementation.

       2. the synchronized when an exception occurs, it will automatically release the thread owns the lock, it will not lead to a deadlock phenomenon; and lock when an exception occurs, if there is no initiative by the unlock () to release the lock, then it is likely to cause death lock phenomenon, it is necessary to release the lock finally use lock.

       3.lock lets wait for the lock thread in response to interrupts, but it's not synchronized, use synhronized, waiting threads will wait forever, can not respond to interrupts.

      4. Adoption of the lock can know without success to obtain a lock, and synchronized can not be done.

      5.lock multiple threads can improve the efficiency of the read operation.

Guess you like

Origin www.cnblogs.com/youdiaodaxue16/p/11432573.html