org.jlot.test.TomcatStartupTimeLogger Maven / Gradle / Ivy
package org.jlot.test;
import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;
public class TomcatStartupTimeLogger implements LifecycleListener
{
final long startTime = System.currentTimeMillis();
private String name;
public TomcatStartupTimeLogger ( String name )
{
this.name = name;
}
@Override
public void lifecycleEvent ( LifecycleEvent event )
{
if (event.getType().equals(Lifecycle.AFTER_START_EVENT))
{
long endTime = System.currentTimeMillis();
int seconds = Math.round( ( endTime - startTime ) / 1000);
String message = String.format("Server in %s Sekunden gestartet: %s", seconds, name);
System.out.println(message);
}
if (event.getType().equals(Lifecycle.AFTER_STOP_EVENT))
{
System.out.println("Server gestoppt: " + name);
}
}
}