1 8 package examples.async; 9 10 import org.codehaus.aspectwerkz.joinpoint.JoinPoint; 11 import org.codehaus.aspectwerkz.joinpoint.MethodSignature; 12 import org.codehaus.aspectwerkz.annotation.*; 13 14 import java.util.concurrent.Executor ; 15 import java.util.concurrent.Executors ; 16 import java.lang.reflect.Method ; 17 18 import is.Async; 19 20 public class AsyncAspect { 21 22 28 private Executor m_threadPool = Executors.newCachedThreadPool(); 29 30 @Around("execution(@is.Async) && within(@is.Service)") 31 public Object async(final JoinPoint jp) throws Throwable { 32 m_threadPool.execute( 35 new Runnable () { 36 public void run() { 37 try { 38 40 Method currentMethod = ((MethodSignature)jp.getSignature()).getMethod(); 42 43 Async theCurrentAnnotation = currentMethod.getAnnotation(Async.class); 45 47 jp.proceed(); 48 } catch (Throwable t) { 49 t.printStackTrace(); 50 } 51 } 52 } 53 ); 54 return null; 55 } 56 57 58 } | Popular Tags |