views:

62

answers:

3

I have a question, I am always asked this in the interviews multiple times--

How is synchronization implemented in java.. I have answered-- using trylock() mechanism using wait, notify ,and notifyAll() methods in java using synchronized blocks using synchronized for class and object level using mutexes for synchronization using re-entrant locks

Are there any better answers to this?/

+1  A: 

If you care about gaining a deep insight on concurrency then a great source is the http://www.javaconcurrencyinpractice.com/ book.

If you simply care about "passing" this question in interview(s?) then http://download.oracle.com/javase/tutorial/essential/concurrency/index.html may do, but still you generally need to practice a bit to understand synchronization so you are in a position where you'll sufficiently answer questions following the extremely vague "How is synchronization implemented in java".

cherouvim
+1 - Buy the book and read it, and you'll be able to do more than answer interview questions.
Stephen C
A: 

Why not read up on Sun's/Oracle's tutorial on Java synchronization? That's the official view.

Peter Jaric
A: 

I'd probably go with something along the lines of what is found here: http://download.oracle.com/javase/tutorial/essential/concurrency/locksync.html

Kevin