Package com.unboundid.util
Annotation Type ThreadSafety
-
@Documented @Retention(RUNTIME) @Target({TYPE,METHOD}) public @interface ThreadSafetyThis annotation type may be used to indicate the level of thread safety for a class or method. Any class or interface which does not include theThreadSafetyannotation should be assumed to be not threadsafe unless otherwise specified in the documentation for that class or interface.
If theThreadSafetyannotation 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 beThreadSafetyLevel.MOSTLY_NOT_THREADSAFEbut a method within that class is declared to beThreadSafetyLevel.METHOD_THREADSAFE, then that method may be invoked concurrently by multiple threads against the same instance. If a class is declared to beThreadSafetyLevel.MOSTLY_THREADSAFEbut a method within that class is declared to beThreadSafetyLevel.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 theThreadSafetyLevel.METHOD_THREADSAFEorThreadSafetyLevel.METHOD_NOT_THREADSAFElevel, and only if the class is annotated with one of theThreadSafetyLevel.MOSTLY_THREADSAFE,ThreadSafetyLevel.MOSTLY_NOT_THREADSAFE, orThreadSafetyLevel.INTERFACE_NOT_THREADSAFElevel. Classes annotated with either theThreadSafetyLevel.COMPLETELY_THREADSAFEorThreadSafetyLevel.NOT_THREADSAFElevels must not provide alternate method-levelThreadSafetyannotations.
Note that there are some caveats regarding thread safety and immutability of elements in the LDAP SDK that are true regardless of the stated thread safety level:-
If an array is provided as an argument to a constructor or a method, then
that array must not be referenced or altered by the caller at any time
after that point unless it is clearly noted that it is acceptable to do
so.
-
If an array is returned by a method, then the contents of that array must
not be altered unless it is clearly noted that it is acceptable to do so.
-
If a method is intended to alter the state of an argument (e.g.,
appending to a
StringBuilderorByteBufferorByteStringBuffer, reading from aReaderor anInputStream, or writing to aWriterorOutputStream), 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.
-
Unless otherwise noted, public static methods may be assumed to be
threadsafe independent of the thread safety level for the class that
contains them.
-
If an array is provided as an argument to a constructor or a method, then
that array must not be referenced or altered by the caller at any time
after that point unless it is clearly noted that it is acceptable to do
so.
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description ThreadSafetyLevellevelThe thread safety level for the associated class, interface, enum, or method.
-
-
-
Element Detail
-
level
ThreadSafetyLevel level
The thread safety level for the associated class, interface, enum, or method.- Returns:
- The thread safety level for the associated class, interface, enum, or method.
-
-