?? performanceproxy.java
字號:
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package smartproxy.proxies;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* This is a smart proxy wrapper that checks performance.
* Since it uses System.currentTimeMillis this will not show any meaningful
* results on short calls, since the Java timer is not granular enough.
*
* Note that it is not tightly bound to the remote object interface,
* and can therefore be reused with any remote object(!)
*
* @author Rickard 謆erg (rickard@dreambean.com)
* @version $Revision:$
*/
public class PerformanceProxy
implements InvocationHandler, java.io.Serializable, LinkedProxy
{
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;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -