@@ -27,7 +27,7 @@ public class CacheRepository {
2727 @ PersistenceContext (unitName = "topcat" )
2828 EntityManager em ;
2929
30- private static final Logger logger = LoggerFactory .getLogger (ConfVarRepository .class );
30+ private static final Logger logger = LoggerFactory .getLogger (CacheRepository .class );
3131
3232 public Object get (String key , Long seconds ){
3333 Cache cache = getCache (key );
@@ -80,27 +80,32 @@ public void remove(String key) {
8080
8181 @ Schedule (hour ="*" , minute ="0" )
8282 public void prune (){
83- Properties properties = Properties .getInstance ();
84- Integer maxCacheSize = Integer .valueOf (properties .getProperty ("maxCacheSize" , "10000" ));
85-
86- TypedQuery <Cache > query = em .createQuery ("select cache from Cache cache order by cache.lastAccessTime desc" , Cache .class );
87- query .setMaxResults (maxCacheSize );
88-
89- List <Cache > caches ;
90- int page = 1 ;
91- while (true ){
92- query .setFirstResult (maxCacheSize * page );
93- caches = query .getResultList ();
94- if (caches .size () > 0 ){
95- for (Cache cache : caches ){
96- em .remove (cache );
83+ try {
84+ Properties properties = Properties .getInstance ();
85+ Integer maxCacheSize = Integer .valueOf (properties .getProperty ("maxCacheSize" , "10000" ));
86+
87+ TypedQuery <Cache > query = em .createQuery ("select cache from Cache cache order by cache.lastAccessTime desc" , Cache .class );
88+ query .setMaxResults (maxCacheSize );
89+
90+ List <Cache > caches ;
91+ int page = 1 ;
92+ while (true ){
93+ query .setFirstResult (maxCacheSize * page );
94+ caches = query .getResultList ();
95+ if (caches .size () > 0 ){
96+ for (Cache cache : caches ){
97+ em .remove (cache );
98+ }
99+ } else {
100+ break ;
97101 }
98- } else {
99- break ;
100102 }
101- }
102103
103- em .flush ();
104+ em .flush ();
105+ } catch (RuntimeException e ) {
106+ // Catch exceptions to prevent the EJBTimerService from crashing
107+ logger .error ("Unhandled exception in prune()" , e );
108+ }
104109 }
105110
106111 private Cache getCache (String key ){
0 commit comments