People talk about two types of multi-threaded locking - object and class. In my knowledge, locking is done on objects only. Let me explain.
Case 1: On objects we create using new or factory methods etc.
Case 1: On objects we create using new or factory methods etc.
void synchronized myMethod(Type param) {
//will lock on the instance used to call this method
}
or
synchronized(this) {
//will lock on current object
}
or
synchronized(obj1) {
//will lock on specified obj1 object
}