Iterator<Entry<Object, StatefulBeanContext>> it = cacheMap.entrySet().iterator();
long now = System.currentTimeMillis();
while (it.hasNext())
{
Entry<Object, StatefulBeanContext> entry = it.next();
StatefulBeanContext centry = entry.getValue();
if (now - centry.lastUsed >= sessionTimeout * 1000)
{
synchronized (centry)
{
if (centry.getCanPassivate())
{
if (!centry.getCanRemoveFromCache())
{
passivationQueue.add(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");
}
}
}
prePassivationCompleted();
StatefulBeanContext ctx;
while ((ctx = passivationQueue.poll()) != null)
{
passivate(ctx);
}