1 22 package org.jboss.aspects.patterns.readwritelock; 23 24 25 import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock; 26 import EDU.oswego.cs.dl.util.concurrent.ReentrantWriterPreferenceReadWriteLock; 27 import org.jboss.aop.joinpoint.MethodInvocation; 28 29 33 public class ReadWriteLockAspect 34 { 35 36 private ReadWriteLock readWriteLock = new ReentrantWriterPreferenceReadWriteLock(); 37 38 public ReadWriteLockAspect() 39 { 40 41 } 42 43 public Object readLockMethod(MethodInvocation invocation) throws Throwable 44 { 45 Object result=null; 46 47 try 48 { 49 readWriteLock.readLock().acquire(); 50 result= invocation.invokeNext(); 51 } 52 finally 53 { 54 readWriteLock.readLock().release(); 55 } 56 return result; 57 } 58 59 public Object writeLockMethod(MethodInvocation invocation) throws Throwable 60 { 61 Object result = null; 62 63 try 64 { 65 readWriteLock.writeLock().acquire(); 66 result= invocation.invokeNext(); 67 } 68 finally 69 { 70 readWriteLock.writeLock().release(); 71 } 72 return result; 73 } 74 75 } 76 | Popular Tags |