ACA Blog

ACA Blog


May 2019
M T W T F S S
« Apr    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories


Timing JSF requests

Jan EerdekensJan Eerdekens

Sometimes you need to be able to determine where exactly time is being spent in your JSF web application. Luckily there is something in the JSF specification that can help us with this task: PhaseListener. A JSF PhaseListener is a mechanism that’s similar to a Java web application filter. It’s a simple interface that a developer can implement that hooks into the livecycle of something. In the case of a web application and a filter this is the HTTP request start and the HTTP response end. For a JSF PhaseListener this is the start and end of the different JSF phases.

To create a PhaseListener that times all the JSF phases separately and also gives a total time we’re going to use the excellent Perf4J library. This library enables us to do simple timing operations in code without needing to resort to calling System.currentTimeMillis() ourselves. Perf4J also has a lot of other nice features that we wont touch on in this post, but that you should definitely check out: Grails/Seam/CDI integeration, Log4J support, graphing capabilities, JMX, annotations, … .

To use Perf4J just add the required dependency to your project, e.g.

Now you need to create a small class with the following content:

 

With this in place you just need to configure your JSF application to use this custom phaselistener by adding the following to your faces-config.xml (after the application tag):

 

After rebuilding and redeploying your application you should see logging similar to this:

 

Belgian Java and Liferay developer with some weird interests, eternal complainer, atheist, skeptic and geocacher.

Leave a Reply

avatar
  Subscribe  
Notify of