java 调试

This article is about techniques which I have used to debug codeBases of various kinds, such as:

本文是关于我用来调试各种代码库的技术,例如:

  1. CodeBase with high concurrent nature.具有高度并发性的CodeBase。
  2. CodeBase with a lot of proprietary (unsupported) libraries.带有许多专有(不受支持)库的CodeBase。
  3. CodeBase with a lot of deprecated/unwanted code.具有许多不推荐使用/不需要的代码的CodeBase。
  4. CodeBase with memory leaks.内存泄漏的CodeBase。
  5. CodeBase where every JVM can talk to every other JVM.每个JVM可以与每个其他JVM进行通信的CodeBase。

So let’s look at them one by one.

因此,让我们一一看一下。

具有高并发性的CodeBase。 (CodeBase with high concurrent nature.)

It may happen that for serving a request, JVM uses many threads for eg:

为了满足请求,JVM可能会使用许多线程,例如:

Req -> tomcatThread-1 -> executorThread-2 -> BizThread-3->…`

Let say, we find that exception is coming in BizThread-3. Now as a debugger, we want to understand the Request flow. But the stacktrace will not be able to provide the complete request flow (for example, what happened in executorThread-2 and what happened in tomcatThread-1 and so on).

假设,我们发现BizThread-3中出现了异常。 现在,作为调试器,我们希望了解请求流。 但是stacktrace将无法提供完整的请求流(例如, executorThread-2中发生的事情以及tomcatThread-1中发生的事情,等等)。

Technique 1.1: Write a custom java-agent which will be used to effectively add log.debug() to the start and end of every method of certain java packages. This will give us some insight into what all is getting called.

技术1.1:编写一个自定义的Java代理 ,该代理将用于将log.debug()有效地添加到某些Java包的每个方法的开头和结尾。 这将使我们对所有被调用的内容有一些了解。

Technique 1.2: In certain frameworks, if supported, use AOP to proxy all methods and effectively add log.debug().

技术1.2:在某些框架中,如果受支持,则使用AOP代理所有方法并有效地添加log.debug()

带有许多专有(不受支持)库的CodeBase。 (CodeBase with a lot of proprietary (unsupported) libraries.)

Sometimes we find ourself in a situation where, after hours of debugging, we nail the problem that xyz-gov-secret library is misbehaving and this library is now unsupported.

有时,我们发现自己处于这样一种情况:经过数小时的调试,我们发现xyz-gov-secret库行为不当,并且现在不支持该库的问题。

Technique 2.1: Roll up your sleeves and install eclipse-decompiler and dive into the code base.

技术2.1:卷起袖子并安装eclipse-decompiler 并深入研究代码库。

具有许多不推荐使用/不需要的代码的CodeBase。 (CodeBase with a lot of deprecated/unwanted code.)

This is a classic one: we sometimes find ourselves in a method of 500+ lines with tons of deprecated if-else. Now, how do we figure out what is the code flow for a particular call, which if-else are going to use, and which is the dead code?

这是一个经典的例子:有时我们会发现自己的方法是使用500多个行,其中包含大量不推荐使用的if-else。 现在,我们如何确定特定调用的代码流是什么,if-else将使用什么,死代码是什么?

Technique 3.1: We can use a tool called jacoco agent. It collects the execution details during runtime and can color-code the code in eclipse.Basically, it is the same tool, generally used in analyzing code coverage by JUnit Test.

技术3.1:我们可以使用称为jacoco agent的工具。 它收集运行时的执行细节,并可以在eclipse中对代码进行颜色编码。基本上,它是同一工具,通常用于JUnit Test分析代码覆盖率。

内存泄漏的CodeBase。 (CodeBase with memory leaks.)

Every developer has a day when, in their local system, all goes good, in production OutOfMemory :(

每个开发人员都有一天在他们的本地系统中一切正常,在生产OutOfMemory中:(

Technique 4.1: JVM provides techniques to capture heap dumps in case of outOfMemory.

技术4.1: JVM提供了在内存不足的情况下捕获堆转储的技术。

Add the following as an argument while starting the JVM -XX:+HeapDumpOnOutOfMemoryError . This will capture the heap dump and put it in a file, which can be used to analyze what is eating up the memory.

在启动JVM -XX时添加以下内容作为参数:+ HeapDumpOnOutOfMemoryError 这将捕获堆转储并将其放入文件中,该文件可用于分析正在消耗内存的内容。

Technique 4.2: You can also take the heap dump/thread dump of a running JVM using jProfiler/Jvisiualvm.

技术4.2:您还可以使用jProfiler / Jvisiualvm获得正在运行的JVM的堆转储/线程转储。

每个JVM可以与每个其他JVM进行通信的CodeBase。 (CodeBase where every JVM can talk to every other JVM.)

When you are thrown into a spaghetti distributed environment, it becomes difficult to track down the request flow.

当您陷入意粉分布式环境时,很难追踪请求流。

Technique 5.1: You can use tools like Wireshark. Wireshark captures the network data and represents it in a nice UI. You can then view the HTTP request/response flowing through the system

技术5.1:您可以使用Wireshark之​​类的工具。 Wireshark捕获网络数据并在一个漂亮的UI中表示它。 然后,您可以查看通过系统的HTTP请求/响应

荣誉奖 (Honorable mentions)

Technique 6.1: In a single-threaded environment, intentionally insert try catch in order to quickly know the stacktrace.

技术6.1:在单线程环境中,有意插入try catch以快速了解stacktrace。

try {throw new RuntimeException();
} catch(Exception e){e.printStackTrace();
}

Technique 6.2: Using eclipse breakpoint or using conditional breakpoint.

技术6.2:使用蚀断点或有条件断点。

Technique 6.3: https://en.wikipedia.org/wiki/Rubber_duck_debugging

技术6.3: https //en.wikipedia.org/wiki/Rubber_duck_debugging

Motivation of article: Team Learning/Knowledge Sharing.

文章动机:团队学习/知识共享。

翻译自: https://www.freecodecamp.org/news/how-to-debug-java-code-4a28442e0959/

java 调试

java 调试_我最喜欢的Java调试技术相关推荐

  1. java 拼图_我最喜欢的Java拼图2 + 1 = 4

    java 拼图 这是我当前最喜欢的Java难题. 您如何获取代码来执行此操作? Integer b = 2; Integer c = 1;System.out.println("b+c : ...

  2. 高级java开发_我最喜欢的Java高级开发人员在线资源

    高级java开发 ProgramCreek.com博客最近发布了两个针对"高级" Java开发人员的有趣帖子:高级Java开发人员的十大书籍和高级Java开发人员的 十大网站 . ...

  3. java安装_我最喜欢的Java高级开发人员书籍

    java安装 我上一篇博客文章(我对高级Java开发人员的十个最喜欢的在线资源)的想法,是由Xiaoran Wang发表的 "面向高级Java开发人员的十大网站"的启发. Wang ...

  4. 高级java开发_我最喜欢的Java高级开发人员书籍

    高级java开发 我上一篇博客文章 (我对高级Java开发人员的十个最喜欢的在线资源)的想法,是由Xiaoran Wang发表的"面向高级Java开发人员的十大网站"的启发. Wa ...

  5. 拼图游戏_我最喜欢的Java拼图2 + 1 = 4

    拼图游戏 这是我当前最喜欢的Java难题. 您如何获取代码来执行此操作? Integer b = 2; Integer c = 1;System.out.println("b+c : &qu ...

  6. scala本地调试_如何编写自己的Java / Scala调试器

    scala本地调试 在本文中,我们将探讨Java / Scala调试器的编写和工作方式. 诸如Windows的WinDbg或Linux / Unix的gdb之类的本机调试器通过操作系统直接提供给它们的 ...

  7. 成为java高手_我如何想成为Java

    成为java高手 我喜欢Java. 我喜欢用Java编程. 但是在使用Python一段时间后,我希望对其进行一些更改. 它几乎纯粹是语法上的,因此可能有更好的JVM语言,但是我并不真正感兴趣,因为我仍 ...

  8. java书籍_非科班,自学java需要把软件工程的课程全部学习完吗?

    问题一:非科班是否能自学Java.问题二:自学Java是否需要把软件工程课程全部学完?问题三:如何自学Java? 解决问题一:非科班是否能自学Java.不知道你是否有这个担心疑虑,从事Java技术开发 ...

  9. java组件_三个必不可少的Java平台组件:什么是JVM,JDK,JRE?有啥区别?

    刚接触Java的开发人员经常想知道Java虚拟机,Java开发工具包和Java运行时环境与众不同的地方.他们也很好奇这三个Java平台组件如何在Java应用程序中一起工作.最后,开发人员需要知道他们将 ...

最新文章

  1. 字符串处理stringr包在微生物生态的应用基础
  2. 分布式WebSocket架构
  3. do not tell much about your past
  4. k8s基础概念:pause容器和pod控制器类型
  5. Apache服务器学习笔记
  6. abb机器人goto指令用法_ABB机器人指令对照---中文
  7. C++ {}作用域 return
  8. 如何利用PHOTOSHOP将图片旋转45度
  9. UEditor的使用方法
  10. 上海学计算机编程,上海自学计算机编程入门
  11. kali工具 -- setoolkit(克隆网站及利用)
  12. 嵌入式课程设计 —— GPIO接口编程
  13. [poj3130][半平面交]How I Mathematician Wonder What You Are!
  14. 打造数智制造“新引擎”,用友U9 cloud助百得胜加速崛起
  15. 提取文件夹中图片名字
  16. 如何将m3u8格式转成MP4以及可播放格式
  17. 《长尾理论》读书笔记------”长尾法则--怎样创造一个消费天堂“
  18. 榕树说技术支持(Rong Zhiyun technical support)
  19. python小工具:文件批量改名
  20. 117页数字化转型与产业互联网发展趋势及机会分析报告(PPT)

热门文章

  1. 结业考试笔记 2014中超联赛项目笔记 0327
  2. java云题库测试使用说明 0917
  3. 爬虫-cookie与session的功能与用途
  4. dj鲜生-02-抽象基类的创建
  5. mysql数据库引擎InnoDB和MyISAM
  6. 深入浅出MyBatis:「映射器」全了解
  7. 迷宫(AHOI2016初中组T3)
  8. Juqery ready的几种写法
  9. 终于知道以后该咋办了!
  10. Nginx配置HTTP2.0