public void testMethod(){

        Test1 t1 = new Test1();
t1.my(); } public static void main(String[] args) {
Test t = new Test();
t.testMethod();
} class Test1{
public void my(){ String tag = this.getMyGrandpaStackTrace();
System.err.println(String.format("调用我的人是:%s", tag));
} public String getMyGrandpaStackTrace(){ StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
StackTraceElement father = stackTrace[1];
StackTraceElement log = stackTrace[2];
String tag = null;
for (int i = 1; i < stackTrace.length; i++) {
StackTraceElement e = stackTrace[i];
if (!e.getClassName().equals(log.getClassName())) {
tag = e.getClassName() + "." + e.getMethodName();
break;
}
}
if (tag == null) {
tag = log.getClassName() + "." + log.getMethodName(); }
System.err.println(String.format("My father is %s.%s", father.getClassName() ,father.getMethodName()));
System.err.println(String.format("My grandpa is %s",tag));
return tag; } }

java 获取当前方法的被调用信息(被那个方法那个类那一行调用)的更多相关文章

  1. 创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。

    创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法). ackage com.chuoji.text01; pub ...

  2. 多级反向代理下,Java获取请求客户端的真实IP地址多中方法整合

    在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的.但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实I ...

  3. java获取cpu、内存、硬盘信息[转]

    http://m.oschina.net/blog/312911 1 下载安装sigar-1.6.4.zip 使用java自带的包获取系统数据,容易找不到包,尤其是内存信息不够准确,所以选择使用sig ...

  4. Java获取此次请求URL以及服务器根路径的方法

    http://www.jb51.net/article/71693.htm ********************************************** 本文介绍了Java获取此次请求 ...

  5. java获取本机IP地址和MAC地址的方法

    // 获取ip地址 public static String getIpAddress() { try { Enumeration<NetworkInterface> allNetInte ...

  6. java获取windows和linux下本机ip通用方法

    public InetAddress getFirstNonLoopbackAddress(boolean preferIpv4, boolean preferIPv6) throws SocketE ...

  7. Java 获取webapp,Root,classpath,项目等路径工具类

    public class UtilPath { public static void main(String[] args) { String systemName = System.getPrope ...

  8. 19.创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。

    package zuoye2; public class People { protected double height; protected double weight; private Stri ...

  9. Java 获取并计算程序执行时间

    一般输出日期时间经常会用到Date这个类: SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// ...

随机推荐

  1. 8个SpringBoot精品项目

    8个SpringBoot精品项目 https://gitee.com/52itstyle/spring-boot-seckill 秒杀 https://gitee.com/52itstyle/spri ...

  2. 【字符串】【P5830】 【模板】失配树

    [字符串][P5830] [模板]失配树 Description 给定一个长度为 \(n\) 的字符串 \(S\),有 \(m\) 次询问,每次询问给定 \(S\) 的两个前缀,求它们的最长公共 bo ...

  3. fork()和vfork()的区别(转载)

    fork和vfork 转载 http://coolshell.cn/articles/12103.html 在知乎上,有个人问了这样的一个问题--为什么vfork的子进程里用return,整个程序会挂 ...

  4. SpringData JPA一对多多对一多对多关联

    一.一对多.多对一 1.Country实体类 2.City实体类 3.CountryDao层 4.CityDao层 5.Controller package com.zn.controller; im ...

  5. Powershell更新

    问题:在vin7电脑启动vagrant up 提示powershell版本过低. 在vin7电脑启动vagrant up 提示powershell版本过低: The version of powers ...

  6. git常用指令汇总

    命令行指令 Git 全局设置 git config --global user.name "cqu2003" git config --global user.email &quo ...

  7. 【神经网络与深度学习】neural-style、chainer-fast-neuralstyle图像风格转换使用

    neural-style 官方地址:这个是使用torch7实现的;torch7安装比较麻烦.我这里使用的是大神使用TensorFlow实现的https://github.com/anishathaly ...

  8. lua entry thread aborted: runtime error: /usr/../process.lua:448: attempt to concatenate field 'np_sum_duration' (a userdata value)

    [1]问题场景原代码 引起问题的原代码,访问数据库,汇总数据后,使用汇总结果报异常: local function amount_sum_fee(cycleid) local select_produ ...

  9. 【数据结构与算法】线性表操作(C++)

    #include <stdio.h> #define maxSize 100 //定义整型常量maxSize值为100 /*顺序表的结构体定义*/ typedef struct SqLis ...

  10. QT攻略——我在QT中遇到的那些坑

    (1)QUdpSocket接收数据 进入槽后,要用这种方式读取,否则可能会导致不发readyRead()信号 .while(udpSocket->bytesAvailable()){ udpSo ...