Concurrency is hot, try the JCIP annotations
Join the DZone community and get the full member experience.
Join For FreeFor all of us, Java programmers, who plan to write software for a couple more years, concurrency is quickly becoming a topic to seriously consider in our short-term study plans. Brian Goetz has written an excellent book for us, named Java Concurrency in Practice, in which he amongs other things comes up with a few handy annotations to express the implied concurrency constrains of the code. These are @ThreadSafe, @NotThreadSafe, @GuardedBy and @Immutable.
Although the opinions on usefulness of these may vary, IntelliJ IDEA in both Community and Ultimate editions now gives you an option to try them for yourself, use them in your code and have the powerful inspection engine continuously check the imposed constraints for you.
So, for example, a class annotated as @Immutable is not supposed to have non-final fields.
IDEA highlights the problem in your code and displayes an explanatory warning message.
Access to fields declared as @GuardedBy is checked for holding the declared lock.
You really have to hold exactly the particular lock you declared with the @GuardedBy annotation.
Also the @GuardedBy annotation itself must for obvious reasons refer to a valid identifier.
In the good IntelliJ IDEA tradition there's nothing you need to do before you start using the feature. Just type any of the annotations in your code and see IDEA adding the appropriate jar file and imports to your project automatically.
Enjoy concurrency!
Opinions expressed by DZone contributors are their own.
Comments