diff --git a/Zutil.jar b/Zutil.jar index 866b125..c3de400 100755 Binary files a/Zutil.jar and b/Zutil.jar differ diff --git a/src/zutil/db/bean/DBBean.java b/src/zutil/db/bean/DBBean.java index ad75c8a..b127fb3 100755 --- a/src/zutil/db/bean/DBBean.java +++ b/src/zutil/db/bean/DBBean.java @@ -449,8 +449,8 @@ public abstract class DBBean { /** * This function cancels the internal cache garbage collector in DBBean */ - public static void cancelGBC(){ - DBBeanSQLResultHandler.cancelGBC(); + public static void enableBeanGBC(boolean enable){ + DBBeanSQLResultHandler.enableBeanGBC(enable); } @@ -461,5 +461,5 @@ public abstract class DBBean { /** * Will be called whenever the bean has been updated from the database. */ - protected void updatePerformed(){} + protected void postUpdateAction(){} } diff --git a/src/zutil/db/bean/DBBeanSQLResultHandler.java b/src/zutil/db/bean/DBBeanSQLResultHandler.java index f06c8dd..c58a921 100755 --- a/src/zutil/db/bean/DBBeanSQLResultHandler.java +++ b/src/zutil/db/bean/DBBeanSQLResultHandler.java @@ -116,20 +116,25 @@ public class DBBeanSQLResultHandler implements SQLResultHandler{ this.bean_config = DBBeanConfig.getBeanConfig( cl ); // Initiate DBBeanGarbageCollector - if( timer == null ){ - timer = new Timer( true ); // Run as daemon - timer.schedule( new DBBeanGarbageCollector(), 10000, CACHE_TTL ); - } + } /** * This function cancels the internal cache garbage collector in DBBean */ - public static void cancelGBC(){ - if( timer != null ){ - timer.cancel(); - timer = null; - } + public static void enableBeanGBC(boolean enable){ + if(enable){ + if( timer == null ){ + timer = new Timer( true ); // Run as daemon + timer.schedule( new DBBeanGarbageCollector(), 10000, CACHE_TTL*2 ); + } + } + else { + if (timer != null) { + timer.cancel(); + timer = null; + } + } } /** @@ -148,27 +153,26 @@ public class DBBeanSQLResultHandler implements SQLResultHandler{ int removed = 0; long time = System.currentTimeMillis(); - Object[] class_keys = cache.keySet().toArray(); - for(Object key : class_keys){ - if( key == null ) continue; + for(Object classKey : cache.keySet()){ + if( classKey == null ) continue; - Map class_cache = cache.get(key); - Object[] bean_keys = class_cache.keySet().toArray(); - for(Object sub_key : bean_keys){ - if( sub_key == null ) continue; + Map class_cache = cache.get(classKey); + for(Object objKey : class_cache.keySet()){ + if( objKey == null ) continue; - DBBeanCache beanCache = class_cache.get(sub_key); + DBBeanCache beanCache = class_cache.get(objKey); // Check if session is still valid - if( beanCache.timestamp + CACHE_TTL*2 < time ){ - class_cache.remove(sub_key); + if( beanCache.timestamp + CACHE_TTL < time ){ + class_cache.remove(objKey); removed++; - logger.finer("Removing old DBBean(id: "+beanCache.bean.getId()+") from cache."); + logger.finer("Removing old DBBean(class: "+beanCache.bean.getClass().getName() + +", id: "+beanCache.bean.getId()+") from cache."); } } } if( removed > 0 ) - logger.info("DBBeanGarbageCollector has cleared "+removed+" beans from cache."); + logger.info("DBBean GarbageCollector has cleared "+removed+" beans from cache."); } } @@ -281,7 +285,7 @@ public class DBBeanSQLResultHandler implements SQLResultHandler{ obj.processing_update = false; } - obj.updatePerformed(); + obj.postUpdateAction(); } /**