由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - a dump method in Java
相关主题
Re: 想起几年前Re: run servlet from command lic到java的转换还有java的怪异错误
这个spring 太恶心了新手请教java generic method 调用问题
AOP这东西听起来很不错Re: JAVA有没有象C中SYSTEM那样的METHOD?
override/overload/overwrite in JavaJava question 101-150
How to intercept a method callWhy no JAVA HTTP Stack?
需要用java记录客户端的行为数据怎么返回一个变量的地址?
c++熟手如何学习Java直到能够参与开发企业级应用?JAVA里什么METHOD是用来STRING PATTERN SEARCH
java.lang.reflect.InvocationTargetExceptionJava的method不都是virtual的么?private就不同了?
相关话题的讨论汇总
话题: method话题: java话题: trace话题: stack
进入Java版参与讨论
1 (共1页)
N*n
发帖数: 456
1
Is it possible to make a dump method in Java, so that when it's called, it
will find out all the variables, methods info, even codes, then output it? I
want it to be a general method, which means the same code working for most
object. It would be better to provide the current variable value.. Are there
such method? Or is it possible?
Thanks!
T*********g
发帖数: 496
2
线程的stack trace你可以拿到,变量值不行。

I
most
there

【在 N*n 的大作中提到】
: Is it possible to make a dump method in Java, so that when it's called, it
: will find out all the variables, methods info, even codes, then output it? I
: want it to be a general method, which means the same code working for most
: object. It would be better to provide the current variable value.. Are there
: such method? Or is it possible?
: Thanks!

N*n
发帖数: 456
3
谢谢。。找了点code在看。。
public class StackTraceExample
{
//private static final Logger logger = Logger.getLogger(StringReplace.class.
getName());
public static void main(String args[])
{
//calling a method to print stack trace further down
first();
}
public static void first()
{
second();
}
private static void second()
{
third();
}
private static void third()
{
//If you want to print stack trace on console than use dumpStack() method
System.err.println("Stack trace of current thread using dumpStack() method
");
Thread.currentThread().dumpStack();
//This is another way to print stack trace from current method
System.err.println("Printing stack trace using printStackTrace() method of
Throwable ");
new Throwable().printStackTrace();
//If you want stack trace as StackTraceElement in program itself than
//use getStackTrace() method of Thread class
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
//Once you get StackTraceElement you can also print it to console
System.err.println("displaying Stack trace from StackTraceElement in Java"
);
for(StackTraceElement st : stackTrace)
{
System.err.println(st);
}
}
}

【在 T*********g 的大作中提到】
: 线程的stack trace你可以拿到,变量值不行。
:
: I
: most
: there

s****l
发帖数: 600
4
aop?

I
most
there

【在 N*n 的大作中提到】
: Is it possible to make a dump method in Java, so that when it's called, it
: will find out all the variables, methods info, even codes, then output it? I
: want it to be a general method, which means the same code working for most
: object. It would be better to provide the current variable value.. Are there
: such method? Or is it possible?
: Thanks!

T*********g
发帖数: 496
5
不可能的。就算可以,这个cost高的让你根本没办法用。

【在 s****l 的大作中提到】
: aop?
:
: I
: most
: there

N*n
发帖数: 456
6
AOP?
Aspect Oriented Programming?
First time knowing it..

【在 T*********g 的大作中提到】
: 不可能的。就算可以,这个cost高的让你根本没办法用。
l**********n
发帖数: 8443
7
you can use interceptor.

【在 N*n 的大作中提到】
: AOP?
: Aspect Oriented Programming?
: First time knowing it..

D*****d
发帖数: 1307
8
reflection?

I
most
there

【在 N*n 的大作中提到】
: Is it possible to make a dump method in Java, so that when it's called, it
: will find out all the variables, methods info, even codes, then output it? I
: want it to be a general method, which means the same code working for most
: object. It would be better to provide the current variable value.. Are there
: such method? Or is it possible?
: Thanks!

1 (共1页)
进入Java版参与讨论
相关主题
Java的method不都是virtual的么?private就不同了?How to intercept a method call
JAVA 求解需要用java记录客户端的行为数据
return null or empty list/set/...c++熟手如何学习Java直到能够参与开发企业级应用?
Which WS stack should I use with JBoss AS ?java.lang.reflect.InvocationTargetException
Re: 想起几年前Re: run servlet from command lic到java的转换还有java的怪异错误
这个spring 太恶心了新手请教java generic method 调用问题
AOP这东西听起来很不错Re: JAVA有没有象C中SYSTEM那样的METHOD?
override/overload/overwrite in JavaJava question 101-150
相关话题的讨论汇总
话题: method话题: java话题: trace话题: stack