Since two threads can't execute different synchronized method at a time. A lock on object is acquired to achieve this. Fair enough, that's what is written in books. Can a synchronized method call another synchronized method ? Consider below example ... can methodA call methodB where both are synchronized ?
class A{
public synchronized void methodA(){
//some operations
methodB();
}
public synchronized void methodB(){
//some operations
}
}
What do you think ?
Well this is answer from SCJP .... Since lock is already acquired methodB will not be able to acquire it again. It would be blocked sort of deadlock. !!!!
No comments:
Post a Comment