Section A.1. Class Annotations

A 1 Class Annotations

We use three class-level annotations to describe a class's intended thread-safety promises: @Immutable, @ThreadSafe, and @NotThreadSafe. @Immutable means, of course, that the class is immutable, and implies @ThreadSafe. @NotThreadSafe is optionalif a class is not annotated as thread-safe, it should be presumed not to be thread-safe, but if you want to make it extra clear, use @NotThreadSafe.

These annotations are relatively unintrusive and are beneficial to both users and maintainers. Users can see immediately whether a class is thread-safe, and maintainers can see immediately whether thread-safety guarantees must be preserved. Annotations are also useful to a third constituency: tools. Static codeanalysis tools may be able to verify that the code complies with the contract indicated by the annotation, such as verifying that a class annotated with @Immutable actually is immutable.

Java Concurrency in Practice
Java Concurrency in Practice
ISBN: 0321349601
EAN: 2147483647
Year: 2004
Pages: 141
Simiral book on Amazon © 2008-2017.
If you may any questions please contact us: