Weaving java.util.concurrent API using AspectJ
June 25, 2012 Leave a comment
I stopped using AspectJ long back because we were not really coding aspects because it required an enormous amount of effort to train others. But recently I wrote this to weave into java.util.concurrent libraries to try to explore how the ForkJoin library works. Even though the code works I thought it is not a recommended way to weave into libraries dealing with concurrency written by experts. I pulled the source and created a custom JAR and used -Xbootclasspath to make it work.
@Aspect public class ForkJoinProjector { @Pointcut( "execution ( int java.util.concurrent.ForkJoinPool.registerWorker(java.util.concurrent.ForkJoinWorkerThread)) &&" + " args(thread) &&" + " target(pool)" ) public void buildQueues( ForkJoinWorkerThread thread, ForkJoinPool pool){} @After("buildQueues( thread,pool)") public void build( ForkJoinWorkerThread thread, ForkJoinPool pool ) { System.out.println( "ID " + thread.getId() + " Name " + thread.getName() ); } }