首页 文章 精选 留言 我的

精选列表

搜索[应用运行环境],共10000篇文章
优秀的个人博客,低调大师

Android线程——StackTraceElement线程运行栈的探索

个人博客CoorChice,https://chenbingx.github.io/ ,最新文章将会首发CoorChice的博客,欢迎探索哦 ! 同时,搜索微信公众号CoorChice,或扫描文章末尾二维码,可以关注我的微信公众号。同期文章也将会优先推送到微信公众号中,以提醒您有新鲜文章出炉。 介绍 StackTraceElement[]中保存了一条线程中所有调用的方法。其中每个方法的信息包含在一个StackTraceElement对象中。 获取StackTraceElement中的信息 element.getClassName(); //获取类名 element.getMethodLine(); //获取方法名 element.getMethodName(); //获取方法名 element.getFileName(); //获取包含类的文件名 StackTraceElement[]中的信息 StackTracelElement[]是一个的数组,以下标0为开始,其中在Java比较有用的是第3个,在Android中比较有用的是第4个,因为在Android中多了一个Dalvik的调用,所以实际Java中的第3位向后移动了一个位置,变成第4位。这个比较有用的StackTraceElement保存了实际调用该方法的方法信息。 //下面方法能够打印一组当前线程的StackTraceElement[]信息: public static String showAllElementsInfo() { String print = ""; int count = 0; //从当前线程中获取所有的StackTraceElement StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); for (StackTraceElement stackTraceElement : stackTraceElements) { count++; print += String.format("ClassName:%s " + "\nMethodName:%s " + "\nMethodLine:%d " + "\n当前是第%d个 " + "\n---------------------------- " + "\n ", stackTraceElement.getClassName(), stackTraceElement.getMethodName(), stackTraceElement.getLineNumber(), count); } return print; } //我是在单元测试中调用的 @Test public void testTestElement() throws Exception { System.out.println(LogUtils.showAllElementsInfo()); } //下面是测试打印结果: ClassName:java.lang.Thread MethodName:getStackTrace MethodLine:1552 当前是第1个 ---------------------------- ClassName:com.example.chenbing.animdvedemo.Utils.LogUtils MethodName:showAllElementsInfo MethodLine:60 当前是第2个 ---------------------------- ClassName:com.example.chenbing.animdvedemo.Utils.LogUtilsTest MethodName:testTestElement MethodLine:32 当前是第3个 ---------------------------- ClassName:sun.reflect.NativeMethodAccessorImpl MethodName:invoke0 MethodLine:-2 当前是第4个 ---------------------------- ClassName:sun.reflect.NativeMethodAccessorImpl MethodName:invoke MethodLine:62 当前是第5个 ---------------------------- ClassName:sun.reflect.DelegatingMethodAccessorImpl MethodName:invoke MethodLine:43 当前是第6个 ---------------------------- ClassName:java.lang.reflect.Method MethodName:invoke MethodLine:498 当前是第7个 ---------------------------- ClassName:org.junit.runners.model.FrameworkMethod$1 MethodName:runReflectiveCall MethodLine:50 当前是第8个 ---------------------------- ClassName:org.junit.internal.runners.model.ReflectiveCallable MethodName:run MethodLine:12 当前是第9个 ---------------------------- ClassName:org.junit.runners.model.FrameworkMethod MethodName:invokeExplosively MethodLine:47 当前是第10个 ---------------------------- ClassName:org.junit.internal.runners.statements.InvokeMethod MethodName:evaluate MethodLine:17 当前是第11个 ---------------------------- ClassName:org.junit.internal.runners.statements.RunBefores MethodName:evaluate MethodLine:26 当前是第12个 ---------------------------- ClassName:org.junit.internal.runners.statements.RunAfters MethodName:evaluate MethodLine:27 当前是第13个 ---------------------------- ClassName:org.junit.runners.ParentRunner MethodName:runLeaf MethodLine:325 当前是第14个 ---------------------------- ClassName:org.junit.runners.BlockJUnit4ClassRunner MethodName:runChild MethodLine:78 当前是第15个 ---------------------------- ClassName:org.junit.runners.BlockJUnit4ClassRunner MethodName:runChild MethodLine:57 当前是第16个 ---------------------------- ClassName:org.junit.runners.ParentRunner$3 MethodName:run MethodLine:290 当前是第17个 ---------------------------- ClassName:org.junit.runners.ParentRunner$1 MethodName:schedule MethodLine:71 当前是第18个 ---------------------------- ClassName:org.junit.runners.ParentRunner MethodName:runChildren MethodLine:288 当前是第19个 ---------------------------- ClassName:org.junit.runners.ParentRunner MethodName:access$000 MethodLine:58 当前是第20个 ---------------------------- ClassName:org.junit.runners.ParentRunner$2 MethodName:evaluate MethodLine:268 当前是第21个 ---------------------------- ClassName:org.junit.runners.ParentRunner MethodName:run MethodLine:363 当前是第22个 ---------------------------- ClassName:org.junit.runner.JUnitCore MethodName:run MethodLine:137 当前是第23个 ---------------------------- ClassName:com.intellij.junit4.JUnit4IdeaTestRunner MethodName:startRunnerWithArgs MethodLine:69 当前是第24个 ---------------------------- ClassName:com.intellij.rt.execution.junit.JUnitStarter MethodName:prepareStreamsAndStart MethodLine:234 当前是第25个 ---------------------------- ClassName:com.intellij.rt.execution.junit.JUnitStarter MethodName:main MethodLine:74 当前是第26个 ---------------------------- ClassName:sun.reflect.NativeMethodAccessorImpl MethodName:invoke0 MethodLine:-2 当前是第27个 ---------------------------- ClassName:sun.reflect.NativeMethodAccessorImpl MethodName:invoke MethodLine:62 当前是第28个 ---------------------------- ClassName:sun.reflect.DelegatingMethodAccessorImpl MethodName:invoke MethodLine:43 当前是第29个 ---------------------------- ClassName:java.lang.reflect.Method MethodName:invoke MethodLine:498 当前是第30个 ---------------------------- ClassName:com.intellij.rt.execution.application.AppMain MethodName:main MethodLine:144 当前是第31个 ---------------------------- CoorChice的公众号

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册