分类 Java 相关 下的文章

JVM HPROF 笔记

HPROF is a tool for heap and CPU profiling shipped with every JDK release. It is a dynamic-link library (DLL) that interfaces with the Java Virtual Machine (JVM) using the Java Virtual Machine Tool Interface (JVM TI). The tool writes profiling information either to a file or to a socket in ASCII or binary format. This information can be further processed by a profiler front end tool.

The HPROF tool is capable of presenting CPU usage, heap allocation statistics, and monitor contention profiles. In addition, it can report complete heap dumps and states of all the monitors and threads in the JVM. In terms of diagnosing problems, HPROF is useful when analyzing performance, lock contention, memory leaks, and other issues.

JVM Troubleshooting 学习笔记

Java Platform, Standard Edition Troubleshooting Guide

Command-line options that are prefixed with -XX are specific to Java HotSpot VM. For more information about command-line options used by Java HotSpot VM, see Java HotSpot VM Command-Line Options.
The jcmd is a new JDK profiling utility in JDK 8. It is suggested to use the latest diagnostic utility, jcmd instead of the earlier jstack, jinfo, and jmap utilities.

core dump 或者 crash dump

core dump:A core dump or a crash dump is a memory snapshot of a running process.

如何获得:

  1. A core dump can be automatically created by the operating system
    when a fatal or unhandled error (for example, signal or system
    exception) occurs.
  2. or can be forced by means of system-provided command-line utilities.
  3. kill -6 on Linux or Solaris systems 将会强制产生一个core 文件,即使程序无响应。
    更多如何获得 参看 这里

IBM JVM(J9) 的javacore 文件和一般进程的core dump 不是一回事。
IBM JVM (J9) java core file: http://www-01.ibm.com/support/docview.wss?uid=swg21393547

Java 变长参数 引起的错误

看下面的代码:

Integer[] values = {1, 2, 3, 4, 5}; 
List<Integer> list = Arrays.asList(values); 
    
int[] numbers = {1, 2, 3, 4, 5};
List<int[]> intList = Arrays.asList(numbers);

为什么第二个变成了 int 数组的 List?看 Arrays.asList的方法:

@SuppressWarnings("varargs")
public static <T> List<T> asList(T... a) {
    return new ArrayList<>(a);
}

它的参数是一个变长参数,可以认为是一个数组。 上面例子第一种情况它认为是 Integer数组,里面包含1到5,5个元素,第二种情况,它认为你传入的是int[][], 并且只包含一个元素,那就是int[]. 对于primary 类型,变长参数估计都是这么理解的。

Microservices architectures pros and cons 微服务架构的优缺点

这里全是引用或者从这篇文章引发的: Microservices - Not A Free Lunch!

pros:

    每个单独的服务都是以某个业务模块为中心, 不用关心其他服务, 开发简单;
    sale out, 伸缩性, HA
    rollback only involve single app
    每个服务都可以根据自己业务特性, 采用不同的内部架构, 工具, 开发语言;
    每个服务可以根据load 情况, 增加减少cluster内机器的数量;
    系统中的服务都是松耦合的, 便于开发, 维护;
    每个服务的开发团队都不至于太大, 团队之间相互独立;
    现在很多的开源的工具支持这种开发模式, 便于上手;

cons:

    原来你测试部署一个app就好了, 那么现在按照模块, 根据微服务架构拆分成了多个app, 相互提供服务, 那么你逻辑上就要有多个team, 多个app, 原来测试, 部署一个app就好了, 现在要部署测试多个app, 要有更多的开发, 测试, 生产环境;
    原来一个app 内部之间直接调用, 现在要通过网络, 要有服务注册, 发现机制; 网络之间的调用, 就有了failover;
    多个prodution cluster 在线上, 那么就需要等多的mnoitor, 报警机制, 以及分布式的log 机制;
    Substantial DevOps Skills Required
    定义接口, 单机应用的接口可以随时改变, 然后修改, 微服务的分布式架构就要求协调多个team, 按计划发布; 并且接口最好在一段时间内不要修改;
    Once we have distributed a system, we have to consider a whole host of concerns that we didn't before. Network latency, fault tolerance, message serialisation, unreliable networks, asynchronicity, versioning, varying loads within our application tiers etc.
    Asynchronicity Is Difficult!
    Testability Challenges