multithreading - Difference between class locking and object locking in Java -
People talk about two types of multi-threaded locking - objects and classes. In my knowledge, locking is done only on objects.
Case 1: We create objects on using or < or case 2: on class Lock is called, and it can be used for stagnant areas or methods or blocks. Economic, because they went to the related class and shared between all objects and other class properties. or I want to know the case of synchronized static methods, lock in which category has been acquired by thread in two cases: This is my understanding yet. Add about or improve on topic. The only difference is that a People talk about two types of multi-threaded locking Object insent lock and item and class not true as you've already done Just because people say stuff it is not true. Often people are very nonsense, in fact, there are entire web sites not estimated in Java: p new or factory methods etc.
zero myMethod (type absolute) {// will lock on the example used to call this method}
synchronize (this) {// will lock on current object}
synchronize (obj1) {// specified obj1 will be locked on object}
java.lang.Class object
Fixed zero synchronized method () {// Class object will lock}
static { Synchronize (SomeClass.class) {int a = 2; }}
java.lang.Class wrapped inside the object created by JVM. So behind the abstract, in its object locking and in the picture, we see class locking.
java.lang.Class example) is not the same as it is not released by the first thread. Works the way. / Li>
static synchronize locks and examples on the class instance But a non-static
synchronize method lock.
lock style lock is a
lock is confusingly both.
Comments
Post a Comment