Over a million developers have joined DZone.

Concurrency is hot, try the JCIP annotations

DZone's Guide to

Concurrency is hot, try the JCIP annotations

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

For 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!

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. 

java ,jetbrains ,ides ,concurrency jcip annotations intellij

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}