I have an issue with my web application and I suspect that the session scoped beans are taking a long time to load.
Is there a way I can log how long the beans are taking to initialize?
I have an issue with my web application and I suspect that the session scoped beans are taking a long time to load.
Is there a way I can log how long the beans are taking to initialize?
You could write a simple time logging mechanism along these lines setting the start time at the beginning of your constructor and the end time in a method annotated with @PostConstruct
. This should give you a good idea how much time Spring takes to initialize your bean and wire up its dependencies.
A simple log4j configuration should enable you to understand how long which bean(s) are taking. Set the logging level to DEBUG and use the date/time format in the log4j appender to print out the times.
SLF4j (that can easily be used with Spring: the reason why I found that) has a special TimeInstrument implementation for such purposes: [StopWatch]
Maybe this helps somebody, even though this question is a little old.
EDIT: The nice thing about it: it actually uses nanoTime() which is - according to these posts[1, 2] - the most precise solution.
(Code snippet from org.slf4j.profiler.StopWatch.start(String) )
public void start(String name) {
this.name = name;
startTime = System.nanoTime();
status = TimeInstrumentStatus.STARTED;
}