Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question about exception thrown from synchronized block of lock method  RSS feed

 
Jianhua Ren
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a synchronized block inside lock method like the following:
synchronized(lockedRecords){
validate(red); //may throw RecordNotFoundException
...
}
Question is that if RecordNotFoundExeption is thrown inside the above synchronized block, does the lock get released? I think it does, just want to confirm with your guys.
Thanks,
Jianhua
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12148
255
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jianhua,
After the exception is thrown, the mutex lock for the lockedRecords object will become available again. Another thread will then be able to aquire that mutex.
Regards, Andrew
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!