Search in sources :

Example 1 with HttpSession

use of org.apache.openejb.server.httpd.HttpSession in project tomee by apache.

the class SessionManager method initEviction.

public void initEviction() {
    if (!"true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.http.eviction", "true"))) {
        return;
    }
    final Duration duration = new Duration(SystemInstance.get().getProperty("openejb.http.eviction.duration", "1 minute"));
    es = Executors.newScheduledThreadPool(1, new DaemonThreadFactory(SessionManager.class));
    es.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            for (final SessionWrapper data : new ArrayList<>(sessions.values())) {
                final HttpSession session = data.session;
                if (session.getMaxInactiveInterval() > 0 && session.getLastAccessedTime() + TimeUnit.SECONDS.toMillis(session.getMaxInactiveInterval()) < System.currentTimeMillis()) {
                    doDestroy(data);
                    sessions.remove(data.session.getId());
                }
            }
        }
    }, duration.getTime(), duration.getTime(), duration.getUnit());
}
Also used : DaemonThreadFactory(org.apache.openejb.util.DaemonThreadFactory) HttpSession(org.apache.openejb.server.httpd.HttpSession) Duration(org.apache.openejb.util.Duration)

Aggregations

HttpSession (org.apache.openejb.server.httpd.HttpSession)1 DaemonThreadFactory (org.apache.openejb.util.DaemonThreadFactory)1 Duration (org.apache.openejb.util.Duration)1