CDI instrumentation

If we focus back on the Metrics library, we will find several CDI integrations. The global idea is to decorate the code with some annotation and automatically get the metrics associated with the executed code. Clearly, it will impact your code this way (using https://github.com/astefanutti/metrics-cdi for instance):

@Transactional@ApplicationScopedpublic class QuoteService {    @PersistenceContext    private EntityManager entityManager;    @Timed(name = "create")    public Quote create(final Quote newQuote) {        entityManager.persist(newQuote);        entityManager.flush();        return newQuote;    }}

The @Timed annotation will automatically wrap the method execution in a Metrics timer and will therefore provide the statistics about the execution time ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.