Iterator it = cacheMap.entrySet().iterator();
long now = System.currentTimeMillis();
while (it.hasNext())
{
Map.Entry entry = (Map.Entry) it.next();
StatefulBeanContext centry = (StatefulBeanContext) entry.getValue();
if (now - centry.lastUsed >= sessionTimeout * 1000)
{
synchronized (centry)
{
if (centry.getCanPassivate())
{
if (!centry.getCanRemoveFromCache())
{
passivate(centry);
}
else if (trace)
{
log.trace("Removing " + entry.getKey() + " from cache");
}
}
else
{
centry.markedForPassivation = true;
assert centry.isInUse() : centry + " is not in use, and thus will never be passivated";
}
// its ok to evict because it will be passivated
// or we determined above that we can remove it
it.remove();
}
}
else if (trace)
{
log.trace("Not passivating; id=" + centry.getId() +
" only inactive " + Math.max(0, now - centry.lastUsed) + " ms");
}
}
}
}