|
From: <jbo...@li...> - 2006-06-11 11:46:47
|
Author: adamw
Date: 2006-06-11 07:46:36 -0400 (Sun, 11 Jun 2006)
New Revision: 4733
Modified:
labs/shotoku/trunk/shotoku-aop/src/java/org/jboss/shotoku/aop/CacheInjectAspect.java
Log:
Bug fixes
Modified: labs/shotoku/trunk/shotoku-aop/src/java/org/jboss/shotoku/aop/CacheInjectAspect.java
===================================================================
--- labs/shotoku/trunk/shotoku-aop/src/java/org/jboss/shotoku/aop/CacheInjectAspect.java 2006-06-11 10:43:54 UTC (rev 4732)
+++ labs/shotoku/trunk/shotoku-aop/src/java/org/jboss/shotoku/aop/CacheInjectAspect.java 2006-06-11 11:46:36 UTC (rev 4733)
@@ -32,30 +32,35 @@
*/
@Aspect(scope=Scope.PER_JOINPOINT)
public class CacheInjectAspect {
- ShotokuCacheItem sci;
+ private final static Object synchronizer = new Object();
+ private ShotokuCacheItem sci;
private CacheItem getCurrentAnnotation(FieldInvocation invocation) {
- CacheItem current = invocation.getField().getAnnotation(CacheItem.class);
- if (current == null)
- throw new RuntimeException("This aspect should be used only with " +
- "@CacheItem!");
+ CacheItem current = invocation.getField().getAnnotation(CacheItem.class);
+ if (current == null)
+ throw new RuntimeException("This aspect should be used only with " +
+ "@CacheItem!");
- return current;
- }
+ return current;
+ }
@Bind(pointcut="field($instanceof{org.jboss.shotoku.cache.ShotokuCacheItem} " +
"*->@org.jboss.shotoku.aop.CacheItem)")
public Object accessCacheItem(FieldReadInvocation invocation) throws Throwable {
if (sci == null) {
- CacheItem ci = getCurrentAnnotation(invocation);
+ synchronized(synchronizer) {
+ if (sci == null) {
+ CacheItem ci = getCurrentAnnotation(invocation);
- if (ci.interval() == 0) {
- sci = (ShotokuCacheItem)
- invocation.getField().getType().getConstructor().newInstance();
- } else {
- sci = (ShotokuCacheItem)
- invocation.getField().getType().getConstructor(Long.TYPE).newInstance(
- ci.interval());
+ if (ci.interval() == 0) {
+ sci = (ShotokuCacheItem)
+ invocation.getField().getType().getConstructor().newInstance();
+ } else {
+ sci = (ShotokuCacheItem)
+ invocation.getField().getType().getConstructor(Long.TYPE).newInstance(
+ ci.interval());
+ }
+ }
}
}
|