关于重定位类,我初次接触是在编写 Spark 应用时遇到,当时业务应用需要用到一个高版本的 Guava 依赖,而 Spark 内置依赖了低版本的 Guava,根据 JVM 默认的类加载顺序,Spark 内置依赖的 Guava 依赖优先于业务依赖的 Guava 版本,导致业务应用出现找不到方法的异常,后通过 Relocating Classes 将指定的包名进行调整以规避同一个应用域中需要加载不同版本相同类名的问题。
Ergonomics
业务方反馈某组应用偶现超时,超时时间为 2s,大概一两天出现一次,经过排查,超时出现的时刻应用正在进行 FullGC,触发原因为 Ergonomics,该组应用未显式设置过 GC 收集器,经查询,该组应用使用的垃圾收集器为 The Parallel Collector,该收集器以吞吐量为目标,并不关注最大暂停时间,且根据 Oracle 的文档及线上的应用测试,在使用该收集器时即使设置了 -XX:MaxGCPauseMillis=<nnn>,也只能提示收集器尽量实现该目标,并不能保证一定能将最大暂停时间控制在设置的最大值。
Java 为什么对常量的修改没有生效?
写这篇文章的起因是前几天同事改了一个常量类中的提示,发布到测试环境后没有生效,正好看 《Java 解惑(谜题 93: 类的战争)》 提到了这个问题,所以写篇文章记录一下。
以下均使用命令行进行演示,至于为什么没有使用 IDE 后面会提到。
先看一个简单的 Constants 类:
1 | /** |
Java Mission Control
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collection framework built into the Oracle JDK. It allows Java administrators and developers to gather detailed low level information about how the Java Virtual Machine (JVM) and the Java application are behaving. Java Mission Control is an advanced set of tools that enables efficient and detailed analysis of the extensive of data collected by Java Flight Recorder. The tool chain enables developers and administrators to collect and analyze data from Java applications running locally or deployed in production environments.

题图为监测 pull-readhub.me 的示例数据。
Java 对象指针压缩
很久之前就看到过 Java 对象指针压缩这个技术,只是一直没具体想为什么要偏移 3 位,好吧,最近才知道原因是因为大多数 JVM 实现都是采用 8 位对齐,所以二进制位中的后三位都是 0。