Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many types of Locks are there in JAVA

I was asked in an interview that how many types of locks are there in java, I knew about Synchronized(this) or synchronized method, and Reentrant Lock. Are there any other kind of locks I can acquire on an Object?

like image 748
Sumit Sagar Avatar asked Dec 19 '22 11:12

Sumit Sagar


1 Answers

I don't know about the job you're interviewing for, but if I asked you that question in an interview, then I would not be looking for a right answer. I'd be trying to start a discussion where you tell me what locking means, how it works, how you use it, what kind of mistakes you or your peers have made with it, and what you learned from your/their mistakes.

I'd be looking to find out whether you understand the differences between locking that's provided by the language vs. locking that is provided by the libraries, vs. locking that's provided by the underlying hardware.

There is no job on Earth that you're disqualified from doing if you don't know exactly how many different kinds of lock are in the Java language, but there are lots of jobs that you shouldn't be doing if you don't know how to talk about it.

like image 64
Solomon Slow Avatar answered Jan 03 '23 06:01

Solomon Slow