package com.jiuqi.mobile.core.service.base.test; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class PerformanceProxy implements InvocationHandler, java.io.Serializable{//, LinkedProxy { private static final long serialVersionUID = -7832210411821763372L; Object next; // Constructors -------------------------------------------------- public PerformanceProxy(Object next) { this.next = next; } // Public -------------------------------------------------------- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Time call long start = System.currentTimeMillis(); try { return method.invoke(next, args); } catch (InvocationTargetException e) { throw e.getTargetException(); } finally { long end = System.currentTimeMillis(); System.out.println(method.getDeclaringClass().getName() + "." + method.getName() + ":" + (end - start) + "ms"); } } public Object getNext() { return next; } public void setNext(Object next) { this.next = next; } }