@Documented @Retention(value=RUNTIME) @Target(value=TYPE) public @interface NotThreadSafe
This annotation is not verified, it is intended for documentation of programmer intent only.
A type may not be annotated with both @ThreadSafe and
@NotThreadSafe.
@ImmutableThread safety and immutability are two points along the same axis. This set of annotations can actually describe three points along the axis:
@Mutable and @NotThreadSafe
@Mutable
, or just @NotThreadSafe. The type contains mutable state
that is not safe to access concurrently from multiple threads.
@Mutable and @ThreadSafe
@ThreadSafe. The type contains
mutable state that is safe to access concurrently from multiple threads.
@Immutable and @ThreadSafe
@Immutable. The type contains no
mutable state, and is thus safe to access concurrently from multiple threads.
The combination @Immutable and
@NotThreadSafe is a modeling error because an immutable
type is obviously thread safe.
java.util are not
thread-safe. This could be documented for java.util.ArrayList, for
example, as shown below.
package java.util;
@NotThreadSafe
public class ArrayList extends ... {
...
}
@annotate tag.
/**
* @annotate NotThreadSafe
*/
public class ArrayList extends ... {
...
}
Implementation note: This annotation is derived from
@NotThreadSafe proposed by Brian Goetz and Tim Peierls in
the book Java Concurrency in Practice (Addison-Wesley 2006) we have
simply adapted it to have semantics as a promise. Further, the annotation in
net.jcip.annotations may be used instead of this one with the same
tool behavior.ThreadSafeCopyright © 2012 Surelogic, Inc.. All Rights Reserved.