Have rules which can static check the validity of Immutable/Mutable ThreadSafe/NotThreadSafe. Annotations should be RUNTIME to allow container to perform additional dynamic checks.
This illustrates the rules which could be used to statically check thread safety This could improve the quality of multi-threaded code.
Immutable:
classes - cannot be changed and are thus thread safe. No mutable method can be called and it and its fields cannot be passed as a Mutable parameter. An immutable class is ThreadSafe.
parameters - means a parameter will not be changed. No Mutable methods can be called on it, nor can be passed to a mutable parameter.
methods - means a method does not alter "this" No calls to method which alter this are allowed.
Mutable:
classes - can be altered. Assumed to be NotThreadSafe unless marked as ThreadSafe.
parameters- means a parameter could be altered. Not valid if it is not altered.
methods - could alter "this". Not valid in an Immutable class.
ThreadSafe:
class - is mutable but thread safe.
parameter - assumes the parameter is thread safe. NotThreadSafe cannot be used.
NotThreadSafe:
class - is mutable. Cannot be used in context which assume thread safety.
parameter - Make no assumption about thread safety./