Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to code with JCIP (Java Concurrency in Practice)

Recently read up on JCIP annotations and they seem cool. Went to the website and took a look at the source. The only problem is that the src jar just contains the annotations...I'm not seeing where I can find the annotation processors that actually do anything! Am I just looking in the wrong place, or are these not real Java annotations (meaning, is there no way to enforce @Immutable when it is used to mark a class)?

  • @Immutable
  • @GuardedBy
like image 770
IAmYourFaja Avatar asked Apr 28 '12 16:04

IAmYourFaja


People also ask

Is Java Concurrency in Practice still valid?

TL: DR — Yes, Java Concurrency in Practice is still valid and one of the best books to learn Java multithreading and concurrency concepts.

Is Java good for concurrency?

While Java isn't necessarily the best language for concurrency, there are a lot of tools, libraries, documentation and best practices out there to help. Using message passing and immutability instead of threads and shared state is considered the better approach to programming concurrent applications.


3 Answers

FindBugs supports those annotations. The support for those annotations and others is described in this documentation page.

like image 185
JB Nizet Avatar answered Oct 19 '22 21:10

JB Nizet


The IntelliJ IDE will use these annotations to look for bugs in your code. If you annotate a variable is @GuardedBy(some_lock), the IDE will flag cases where you access it without properly synchronizing on it. This is very useful.

like image 37
MiguelMunoz Avatar answered Oct 19 '22 20:10

MiguelMunoz


The JCIP annotations are a formal way to document a concurrency contract such as this member is "@GuardedBy" this field.

They don't do anything functionally in your code.

like image 1
Victor Grazi Avatar answered Oct 19 '22 19:10

Victor Grazi