jQuery in Action, 3rd edition
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Key to locking success: Java Memory Model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Key to locking success: Java Memory Model" Watch "Key to locking success: Java Memory Model" New topic

Key to locking success: Java Memory Model

Chris Be
Ranch Hand

Joined: Sep 11, 2006
Posts: 36
A hint to anyone working on the locking: the key to success is the "Java Memory Model".

With your code level instructions, or as in my case at times the lack of such, your compiler will receive instructions on on how your specified code execution order may be reorderable when it actually runs. And the compiler/jvm's interpretation will vary between java versions!

So, your code may actually execute in another order to what you think it is according to your written code.

JSR-133 and JSR-166 with related articles gave me some AHA effects on my unexpectedly poor locking score.

I would dare to say if you are using, but not fully across the Java Memory Model implication of synchronize AND volatile AND final (or equivalent util.concurrent abstractions), your locking may likely be (like mine) in elements inferior/incomplete. This is not to say it doesn't work on your machine, but will it on a dual or quad core, or in exceptional conditions (e.g. exttremely high load), or with another java version?

If you are not across java concurrency as above, listen to this podcast for an instant AHA effect .

Have fun understanding Java better than many others.

[ February 19, 2008: Message edited by: Chris Be ]
[ February 19, 2008: Message edited by: Chris Be ]

ChrisBe<br />-------<br />SCJP, SCJD, SCEA in the making
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Wow, thanks Chris, as always your post are really informative (last one being the anti-patterns for Exception).

You really opened my eyes on a beast. I didn't even begin to suspect such thing.

I agree. Here's the link: http://aspose.com/file-tools
subject: Key to locking success: Java Memory Model
It's not a secret anymore!