Assume I have following class
class Student{
void method1(){
// Do Something
}
void method2(){
// Do Something
}
}
And the object of this class is used as monitor in synchronization in some piece of the code as
class ProcessingThread implements Runnable {
void someMethod(){
synchronized(student){ // student object is used as lock. Thread T1 acquires a lock on student.
// critical section of code
}
}
}
When a thread T1 acquires a lock on the student object, and enters into the critical section of the code, at the same time can some another thread T2 executes a method on the student object i.e.
class College{
void assignTopic(){
student.method1(); // Thread T2 working on student object when
// Thread T1 has acquired a lock on student
}
}
I want to know that what happens to the methods / variables of the locked object when it is acquired by a thread?