[concurrency-interest] Useful concurrency aspect

Ashley Williams ashpublic at mac.com
Tue Jun 23 17:46:14 EDT 2009


Here is another helper that can enforce a subset of immutable for  
aspectj projects.
It gets the compiler to check that any class marked with the Immutable  
annotation doesn't (effectively) contain any non final fields.
The aspect/annotation should probably be changed to something like  
"JustFinals" since I now realize the definition of immutable isn't  
quite so
straightforward:

public aspect ImmutablePolicy {
	declare error : set(!static !final * (@Immutable *).*) : "immutable  
classes can't assign to non final fields";
	
	@Target(ElementType.TYPE)
	@Retention(RetentionPolicy.RUNTIME)
	@ThreadSafe
	public static @interface Immutable {
	}
}

However there must be a great deal of boilerplate code and design  
pattern enforcement that aspectj can help with. The most obvious
one that springs to mind is some around advice that surrounds a method  
with a reentrant lock that makes sure it is released correctly.
In fact if I recall correctly, one of the objections in the jcip book  
for not abandoning intrinsic locks was that it is easy to forget to  
release
reentrant locks.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090623/6f5a8dfa/attachment.html>


More information about the Concurrency-interest mailing list