use of org.apache.openejb.util.DaemonThreadFactory 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());
}
use of org.apache.openejb.util.DaemonThreadFactory in project tomee by apache.
the class ThreadStackRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
if (System.getProperty("os.name", "unknown").toLowerCase().startsWith("windows")) {
return base;
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
final ScheduledExecutorService ses = Executors.newScheduledThreadPool(1, new DaemonThreadFactory(ThreadStackRule.class.getSimpleName() + "-"));
final ScheduledFuture<?> task = ses.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
String pid = bean.getName();
if (pid.contains("@")) {
pid = pid.substring(0, pid.indexOf("@"));
}
try {
Pipe.pipe(Runtime.getRuntime().exec("kill -3 " + pid));
} catch (final Exception exception) {
exception.printStackTrace();
}
}
}, 2, 2, TimeUnit.MINUTES);
try {
base.evaluate();
} finally {
task.cancel(true);
ses.shutdownNow();
}
}
};
}
Aggregations