我想编写一个简单的java代理,它可以打印由java程序调用的方法的名称.
例如,我想要的java程序是:
public class TestInstr {
public static void sayHello() {
System.out.println("Hello !");
}
public static void main(String args[]) {
sayHello();
sayHello();
sayHello();
}
}
Run Code Online (Sandbox Code Playgroud)
我想展示这样的东西:
method sayHello has been called
Hello !
method sayHello has been called
Hello !
method sayHello has been called
Hello !
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
有没有办法可以记录/记录/监视/查看Java程序内每个方法的执行.
例如:
12:30:12 someMethod("argument")
12:30:12 anotherMethos(1, 2, 3)
12:30:13 finalMethod("invalidInputHere1234")
Run Code Online (Sandbox Code Playgroud) 我有一个DAO类,有很多方法,有很多重复的代码:
public void method1(...) {
Connection conn = null;
try {
//custom code here
} catch (SQLException e) {
LOG.error("Error accessing the database.", e);
throw new DatabaseException();
} catch (QueryNotFoundException e) {
LOG.error("Error accessing the database.", e);
throw new DatabaseException();
} finally {
if (conn != null)
connectionPool.returnConnection(conn);
}
public void method2(...) {
Connection conn = null;
try {
//different custom code here
} catch (SQLException e) {
LOG.error("Error accessing the database.", e);
throw new DatabaseException();
} catch (QueryNotFoundException e) …Run Code Online (Sandbox Code Playgroud)