A class has has 2 synchronized functions. If a thread enters one of the synchronized function, then is it possible for a second thread to enter second synchronized function?

Questions by nathanijatin

Showing Answers 1 - 3 of 3 Answers

sekhar

  • Apr 24th, 2006
 

NO other thread can not access other synchronized method.since to access the synchronized method that thread must aquire the lock for that perticular object(class in case os class lock).But that lock of the object is already hold by first thread.so the second thread must wait until the first thread releases the lock(first thread release the lock only when it complets executing synchronized method).

  Was this answer useful?  Yes

Nishant

  • Apr 26th, 2006
 

well it is possible for the 2nd thread to enter second synchronized function as functions are declared synchronized not the class, so there will be a lock aquired on the fuctions not on the class.

  Was this answer useful?  Yes

Manivannan Palanichamy

  • Aug 2nd, 2006
 

The question should be made clear first. See, if a thread enters into a 'synch'ed method of an object, it can still enter into another 'synch'ed method of *same object*. This is known as thread re-entrant. Otherwise, just think, it will lead to deadlock.

It may or may not enter into synch method of *other object* depending on the lock availability of that object.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions