com.swcguild.aspects.SimpleTimerAdvice.java Source code

Java tutorial

Introduction

Here is the source code for com.swcguild.aspects.SimpleTimerAdvice.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.swcguild.aspects;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 *
 * @author apprentice
 */
public class SimpleTimerAdvice {

    public Object timeMethod(ProceedingJoinPoint jp) {
        Object ret = null;

        try {
            long start = System.currentTimeMillis();
            ret = jp.proceed();
            long end = System.currentTimeMillis();
            System.out.println("*************");
            System.out.println(jp.getSignature().getName() + " took " + (end - start) + "ms");
            System.out.println("*************");

        } catch (Throwable ex) {
            System.out.println("Exception occurred in SimpleTimerAdvice.timeMethod()");
        }

        return ret;

    }

}