@Documented @Retention(value=RUNTIME) @Target(value={TYPE,METHOD}) public @interface ThreadSafety
ThreadSafety
annotation should be assumed to be not threadsafe unless
otherwise specified in the documentation for that class or interface.
ThreadSafety
annotation is applied to a method, then it will
override the class-level annotation for the scope of that method. That is,
if a class is declared to be ThreadSafetyLevel.MOSTLY_NOT_THREADSAFE
but a method within that class is declared to be
ThreadSafetyLevel.METHOD_THREADSAFE
, then that method may be invoked
concurrently by multiple threads against the same instance. If a class is
declared to be ThreadSafetyLevel.MOSTLY_THREADSAFE
but a method
within that class is declared to be
ThreadSafetyLevel.METHOD_NOT_THREADSAFE
, then that method must not be
invoked on an instance while any other thread is attempting to access the
same instance. Methods within a class may only be annotated with either the
ThreadSafetyLevel.METHOD_THREADSAFE
or
ThreadSafetyLevel.METHOD_NOT_THREADSAFE
level, and only if the class
is annotated with one of the ThreadSafetyLevel.MOSTLY_THREADSAFE
,
ThreadSafetyLevel.MOSTLY_NOT_THREADSAFE
, or
ThreadSafetyLevel.INTERFACE_NOT_THREADSAFE
level. Classes annotated
with either the ThreadSafetyLevel.COMPLETELY_THREADSAFE
or
ThreadSafetyLevel.NOT_THREADSAFE
levels must not provide alternate
method-level ThreadSafety
annotations.
StringBuilder
or ByteBuffer
or
ByteStringBuffer
, reading from a Reader
or an
InputStream
, or writing to a Writer
or
OutputStream
), then that object provided as an argument must not
be accessed by any other thread while that method is active unless it is
clearly noted that it is acceptable to do so.
Modifier and Type | Required Element and Description |
---|---|
ThreadSafetyLevel |
level
The thread safety level for the associated class, interface, enum, or
method.
|
@NotNull public abstract ThreadSafetyLevel level