@Documented @Retention(value=RUNTIME) @Target(value={CONSTRUCTOR,FIELD,METHOD,TYPE}) public @interface ThreadSafe
The indication of thread safety applies to a field, constructor or method. It never applies to an object read from the field, or created by the constructor, or returned by the method. (Thread-safe fields, constructors and methods are not constrained to dispense only thread-safe objects.) Each object's own thread safety is specified by its own API documentation.
The opposite of ThreadSafe is ThreadRestricted.
An unannotated field is assumed to be thread safe only if it is final. For non-final fields, the safety of access (read or write) is specified by the rules of the language (particularly by the memory model, chapter 17). Strictly speaking, only certain types of volatile field (and their equivalents in java.util.concurrent.atomic) can be thread safe. All others are subject to possibile read/write caching of field values, by threads (caches being flushed at synchronization points).
An unannotated constructor is assumed to be thread safe.
The thread safety of a call, such as object.method(), depends on the object's type (T), where T = object.getClass(). To determine the thread safety of the call:
Or use ThreadSafe.U to perform these same tests at runtime.
Annotation of a class or interface specifies the default thread safety for its public methods. Only methods have such defaults, fields, constructors and static member classes do not. See the rules above for determining the thread safety of a method call.
An unannotated Throwable is assumed to be thread safe.
ThreadRestricted