Over a million developers have joined DZone.

Concurrency is hot, try the JCIP annotations

· Java Zone

Learn more about how the Java language, tools and frameworks have been the foundation of countless enterprise systems, brought to you in partnership with Salesforce.

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!

Discover how the Force.com Web Services Connector (WSC) is a code-generation tool and runtime library for use with Force.com Web services, brought to you in partnership with Salesforce.

java,jetbrains,ides,concurrency jcip annotations intellij

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}