changed name of function to turn of GBC in DBBean and some refactoring in the GBC
This commit is contained in:
parent
7466e02fd9
commit
3f12f5cc45
3 changed files with 29 additions and 25 deletions
BIN
Zutil.jar
BIN
Zutil.jar
Binary file not shown.
|
|
@ -449,8 +449,8 @@ public abstract class DBBean {
|
||||||
/**
|
/**
|
||||||
* This function cancels the internal cache garbage collector in DBBean
|
* This function cancels the internal cache garbage collector in DBBean
|
||||||
*/
|
*/
|
||||||
public static void cancelGBC(){
|
public static void enableBeanGBC(boolean enable){
|
||||||
DBBeanSQLResultHandler.cancelGBC();
|
DBBeanSQLResultHandler.enableBeanGBC(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -461,5 +461,5 @@ public abstract class DBBean {
|
||||||
/**
|
/**
|
||||||
* Will be called whenever the bean has been updated from the database.
|
* Will be called whenever the bean has been updated from the database.
|
||||||
*/
|
*/
|
||||||
protected void updatePerformed(){}
|
protected void postUpdateAction(){}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,20 +116,25 @@ public class DBBeanSQLResultHandler<T> implements SQLResultHandler<T>{
|
||||||
this.bean_config = DBBeanConfig.getBeanConfig( cl );
|
this.bean_config = DBBeanConfig.getBeanConfig( cl );
|
||||||
|
|
||||||
// Initiate DBBeanGarbageCollector
|
// 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
|
* This function cancels the internal cache garbage collector in DBBean
|
||||||
*/
|
*/
|
||||||
public static void cancelGBC(){
|
public static void enableBeanGBC(boolean enable){
|
||||||
if( timer != null ){
|
if(enable){
|
||||||
timer.cancel();
|
if( timer == null ){
|
||||||
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<T> implements SQLResultHandler<T>{
|
||||||
|
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
Object[] class_keys = cache.keySet().toArray();
|
for(Object classKey : cache.keySet()){
|
||||||
for(Object key : class_keys){
|
if( classKey == null ) continue;
|
||||||
if( key == null ) continue;
|
|
||||||
|
|
||||||
Map<Long,DBBeanCache> class_cache = cache.get(key);
|
Map<Long,DBBeanCache> class_cache = cache.get(classKey);
|
||||||
Object[] bean_keys = class_cache.keySet().toArray();
|
for(Object objKey : class_cache.keySet()){
|
||||||
for(Object sub_key : bean_keys){
|
if( objKey == null ) continue;
|
||||||
if( sub_key == null ) continue;
|
|
||||||
|
|
||||||
DBBeanCache beanCache = class_cache.get(sub_key);
|
DBBeanCache beanCache = class_cache.get(objKey);
|
||||||
// Check if session is still valid
|
// Check if session is still valid
|
||||||
if( beanCache.timestamp + CACHE_TTL*2 < time ){
|
if( beanCache.timestamp + CACHE_TTL < time ){
|
||||||
class_cache.remove(sub_key);
|
class_cache.remove(objKey);
|
||||||
removed++;
|
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 )
|
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<T> implements SQLResultHandler<T>{
|
||||||
obj.processing_update = false;
|
obj.processing_update = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.updatePerformed();
|
obj.postUpdateAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue