use of java.lang.management.RuntimeMXBean 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