Example usage for org.apache.commons.collections MapIterator remove

List of usage examples for org.apache.commons.collections MapIterator remove

Introduction

In this page you can find the example usage for org.apache.commons.collections MapIterator remove.

Prototype

void remove();

Source Link

Document

Removes the last returned key from the underlying Map (optional operation).

Usage

From source file:com.inbravo.scribe.rest.service.crm.cache.CRMSessionCache.java

public final void initialize() {
    if (cacheManager != null) {
        cacheManager.cancel();/*from   w  w w. ja va 2s  .  c  om*/
    }
    cacheManager = new Timer(true);
    cacheManager.schedule(new TimerTask() {
        public void run() {
            long now = System.currentTimeMillis();
            try {
                MapIterator itr = cacheMap.mapIterator();
                while (itr.hasNext()) {
                    Object key = itr.next();
                    final CachedObject cobj = (CachedObject) itr.getValue();
                    if (cobj == null || cobj.hasExpired(now)) {

                        if (logger.isDebugEnabled()) {
                            logger.debug("----Inside CRMSessionCache: removing " + key + ": Idle time= "
                                    + (now - cobj.timeAccessedLast) + "; Stale time= " + (now - cobj.timeCached)
                                    + "; Object count in cache= " + cacheMap.size());
                        }
                        itr.remove();
                        Thread.yield();
                    }
                }
            } catch (ConcurrentModificationException cme) {
                /*
                 * This is just a timer cleaning up. It will catch up on cleaning next time it runs.
                 */
                if (logger.isDebugEnabled()) {
                    logger.debug("----Inside CRMSessionCache:Ignorable ConcurrentModificationException");
                }
            }
        }
    }, 0, tiv);
}