[concurrency-interest] Project Lombok: synchronization on private field without the boilerplate

Roel Spilker R.Spilker at topdesk.com
Tue Jul 28 20:11:14 EDT 2009

Hi all,
I think you might find this interesting:
Project Lombok extends both Eclipse and your javac with a few new language features, and one of them is useful for concurrency: By annotating any method with @Synchronized, the method is synchronized, but not on itself ('this'), but on an automatically created private final field named "$lock". Also works with static methods (static $LOCK is generated), and you can specify your own lock (though in that case, you'll have to write the field yourself) as well. It's even smart enough to initialize the lock variable with "new Object[0];" instead of the usual "new Object();", because the former serializes just fine whereas the latter won't.
Full Disclosure: It's my project (with the help from some friends).
Project Lombok might be the solution for the ParallelArray issue: Now we no longer need closures to make using parallel array acceptable. Something like this:
for (@Parallel String name : names ) {
    System.out.println("Look ma! " + name + " is running in parallel!");
could be automatically translated to the proper ParallelArray calls and accompanying anonymous inner class literal for the foreach body. 'final' could even be added to any referenced local variables (or, to go even further, wrap them in an AtomicReference!)
There's a less than 4 minute video on the front page that demonstrates how it works and walks you through the installation process.
Let me know what you think! http://projectlombok.org/ 

 --Roel Spilker

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090729/2cd79369/attachment.html>

More information about the Concurrency-interest mailing list