Subj : Re: Synchronization constructs in Java and their implications To : comp.programming.threads From : Joe Seigh Date : Mon Sep 26 2005 09:50 am Minkoo Seo wrote: > Firstly, I'd like to thank you for your reply. Please, let me leave > 'Spinlock' case out. I made a mistake regarding the spin lock > construct. Anyway, I still have questions about the other constructs. > Following is the code to get a lock using synchronized/Semaphore/Re- > entrantLock: [...] > To me, all three seem to try to get a lock in a quite similar > fashion. But, their performance are different. What's the reason? > Could you elaborate? > You need to look at the source for those constructs. They're probably using the interlocked compare and swap methods from the JSR-166 Atomic stuff to implement a lock. It's possible that compare and swap is faster than the monitorenter instruction for uncontended lock acquisition, though I'd be surprised if that was the case given the performance sensitivity of monitorenter. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .