Make delicious recipes!



JCIP Annotations

JCIP stands for Java Concurrency in Practice.

It is a book which also publishes a small library defining 4 annotations:

  1. GuardedBy

  2. ThreadSafe

  3. NotThreadSafe

  4. Immutable


Last 3 among the above are meant to annotate classes while the first one is used to annotate fields and variables. Example:

@GuardedBy("someLock")

private Integer someVar;

The above annotation indicates that the “someVar” must be accessed only when guarded by “someLock” lock.

Annotating classes and fields in this manner does not affect the runtime in any way. It simply helps the users (and also people who maintains the code later) to understand the behavior of a class/field.

For example, if a class is annotated ThreadSafe, then its users can have more confidence in accessing that class with multiple threads.

Another benefit is that tools like FindBugs can warn against possible use of a class/variable which violates the annotation.

For example, if a variable is annotated with GuardedBy annotation, then the tool can warn if somewhere it’s accessed without a lock.




Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal