「OpenJDK」

认识

官网:http://openjdk.java.net/

性质

内存限制(Memory Limits)

Java 8u131+ / Java 9+:通过 -XX:+UseContainerSupport(默认启用),JVM 自动从 cgroup 读取内存限制(如 Docker 的 -m 参数),并据此设置堆大小。
示例:容器限制 1GB 内存时,JVM 堆默认约为容器内存的 1/4(250MB),而非宿主机内存。

-XX:MaxRAMPercentage=75.0 # 堆最多占用容器内存的 75%
-XX:InitialRAMPercentage=50.0

旧版本(Java 8u131 前):需手动指定堆大小(-Xmx),否则可能超限触发 OOM。

CPU 限制(CPU Limits)

Java 8u191+ / Java 9+:UseContainerSupport 启用后,JVM 自动根据 cgroup 的 CPU 配额(如 –cpus=2)调整线程池大小(GC/ 编译器线程等)。

旧版本,可能误用宿主机 CPU 核数,需手动指定线程数:
-XX:ParallelGCThreads=2 # 手动设置 GC 线程数
-XX:CICompilerCount=2 # 设置 JIT 编译线程数

构建

版本选择

各个版本 JDK 下载地址 | https://jdk.java.net/archive/

JDK 8 http://download.java.net/openjdk/jdk8/
JDK 7 http://download.java.net/openjdk/jdk7/
JDK 6 http://download.java.net/openjdk/jdk6/

容器镜像 | Container Image

DockerHub

[I] SRC: docker.io/library/openjdk:8-jre
[I] DST: ccr.ccs.tencentyun.com/d3rm-3rd/docker.io_library_openjdk:8-jre

[I] SRC: docker.io/library/openjdk:1.8.0
[I] DST: ccr.ccs.tencentyun.com/d3rm-3rd/ocker.io_library_openjdk:1.8.0

[I] SRC: docker.io/library/openjdk:11.0.16
[I] DST: ccr.ccs.tencentyun.com/d3rm-3rd/docker.io_library_openjdk:11.0.16

for Debian

How to install JDK sources?

安装 OpenJDK 的源码包(以 OpenJDK 8 为例):

apt-get install openjdk-8-source

安装后的目录位于:/usr/lib/jvm/java-8-openjdk-amd64/src.zip

with asdf

https://github.com/halcyon/asdf-java.git

asdf plugin list all | grep -i java
asdf plugin add java

asdf install java adoptopenjdk-11.0.16+8
asdf set java adoptopenjdk-11.0.16+8

创建及构建应用(Create and Build Applications)

appletviewer
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/appletviewer.html#BGBEAIGG
appletviewer 提供了一个 Java 运行环境,可在浏览器外部运行 Applet;

extcheck
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/extcheck.html
Detects version conflicts between a target Java Archive (JAR) file and currently installed extension JAR files.

jar
JAR 文件操作程序;用于将多个文件打包成一个 JAR 文件,或者解压 JAR 文件。

javadoc
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javadoc.html#CHDIBDDD
to generate API documentation from javadoc™ comments

java
启动器,用于启动 JVM 示例来运行 Java 应用程序。

javac,读取 Java 类和接口定义,并将其编译为 bytecode 和.class 文件。

javah
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/javah.html#BJEEFAIG
to generate C header files for native methods
javah produces C header and C source files from a Java class.

javap
Java Class 文件反汇编器。

jdb
Java 的一个命令行调试环境,既可在本地,也可在与远程的解释器的一次对话中执行;

jdeps
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jdeps.html#BACEHAGD
Java class dependency analyzer.

Security tools

keytool
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html#CHDBGFHE
Manages a keystore (database) of cryptographic keys, X.509 certificate chains, and trusted certificates.

jarsigner
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jarsigner.html#CCHEAHCH
Signs and verifies Java Archive (JAR) files.

policytool
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/policytool.html#BABECFFA
Reads and writes a plain text policy file based on user input through the utility GUI.

Deploy Applications and Applets

pack200
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/pack200.html#CHDDCCCC
Packages a JAR file into a compressed pack200 file for web deployment.

unpack200
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/unpack200.html#BABDDHFE
Transforms a packed file produced by pack200(1) into a JAR file for web deployment.

Monitor the JVM

jps
MK:显示指定系统内所有的 HotSpot 虚拟机 进程,并且该命令仅报告有访问权限的 JVM 的信息;

jstat: JVM Statistics Monitoring Tool,用于收集 HotSpot 虚拟机各方面运行数据、统计信息,包括 GC、类加载、JIT 信息等;

http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html#BEHHGFAE

jstatd
功能:

java 虚拟机的 jstat 守护程序—启动一个 RMI 服务器程序来监视各个 HotSpot java 虚拟机的创建和中止。并且提供了一个访问远程监视工具接入的接口。

jstatd 是一个 Java 远程方法调用(RMI)服务器应用程序-它监控测量 Java HotSpot 虚拟机的创建和终止并且提供一个接口来允许远程监控工具依附到运行于本地主机的 JVM(请参考《jstatd-Virtual Machine jstat Daemon》)。

 在应用系统中的使用

 jps 及其它 jvmstat 实用程序都使用极为轻量级的观察机制。由 JVM 分配一小部分共享内存,而性能计数器也是从这部分内存中分配的。JVM 子系统基于其感兴趣的事件更新性能计数器。客户端工具仅仅负责异步地从共享内存段中进行读取。因此,总的来说,使用 jvmstat 进行监控的效果是很小的。

Monitor Java Applications

jconsole
J2SE 监测和管理控制台—一个同 JMX 兼容的监测 Java 虚拟机的图形工具。其能够监视当地或者远程的 Java 虚拟机。

Java 监视和管理控制台,JConsole 使用 JVM 的可扩展性 Java 管理扩展(JMX)工具来提供关于运行于 Java 平台的应用程序的性能和资源消耗的信息。

在 J2SE 5.0 软件中,你需要启动使用-Dcom.sun.management.jmxremote 选项监控的应用程序。注意:在 Java SE 6 软件中,不再有这一要求。当启动该应用程序时,不需要特定的命令行选项。

在生产系统中的应用,JConsole 启动一个在被观察的 Java 程序的 JVM 内部的 JMX 代理。运行另外一部分代码仅有一点极微弱的影响-但是影响很小。

  另外,尽管 JConsole 在监视本地应用程序的开发和快速原型开发中很有用,但在实际的应用系统中不推荐使用。理由是,JConsole 本身也消耗大量的系统资源。我们推荐的方法是用远程监控来把 JConsole 应用程序与被监控的系统加以隔离。因此,对于应用系统来说,以远程模式使用 JConsole 更好些。对于安全的远程监控来说,可以使用安全选项。

用法:具有图形界面,可直接操作,查看摘要、内存、线程、类、MBean,VM 的信息。

Remote Method Invocation (RMI)

rmic
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/rmic.html#CIHCDBFH
http://blog.sina.com.cn/s/blog_553a9295010005n3.html
rmic 为远程对象生成 stub 和 skeleton。
Generates stub, skeleton, and tie classes for remote objects that use the Java Remote Method Protocol (JRMP) or Internet Inter-Orb protocol (IIOP). Also generates Object Management Group (OMG) Interface Definition Language (IDL)

rmid
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/rmid.html#CIHCJFEI
rmid 启动激活系统守护进程,以便能够在 Java 虚拟机上注册和激活对象。
Starts the activation system daemon that enables objects to be registered and activated in a Java Virtual Machine (JVM).

rmiregistry
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/rmiregistry.html#CHDEEAFJ
rmiregistry 命令可在当前主机的指定端口上启动远程对象注册服务程序。
Starts a remote object registry on the specified port on the current host.

serialver
http://docs.oracle.com/javase/8/docs/technotes/tools/windows/serialver.html
Returns the serial version UID for specified classes.

故障排除与调试(Troubleshooting)

jinfo: Configuration Info for Java,获取虚拟机的配置信息,也可以在运行期间修改参数;
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jinfo.html#BCGEBFDD

MK:显示虚拟机配置信息;

jmap: Memory Map for Java,生成虚拟机的内存转储快照(headdump 文件),或者共享对象的内存映射;打印进程、核心转储文件、远程调试服务的 so 内存映射或者堆内存的详细信息。

http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jmap.html#CEGCECJB
Prints shared object memory maps or heap memory details for a process, core file, or remote debug server.
This command is experimental and unsupported.

jmap 版本要和程序运行的版本相同,否则会返回类似的错误:Error attaching to process: sun.jvm.hotspot.runtime.VMVersionMismatchException: Supported versions are 25.72-b15. Target VM is 25.73-b02

jcmd

jhat: JVM Heap Dump Browser

MK:用于分析 heapdump 文件,介于 web 服务器;

http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jhat.html#CIHHJAGE
Analyzes the Java heap.
This command is experimental and unsupported.

jsadebugd

http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jsadebugd.html#BHBCGGGH
Attaches to a Java process or core file and acts as a debug server.
This command is experimental and unsupported.

jstack
为 Java 进程、核心文件、远程调试服务器打印 Java 线程栈跟踪。

Scripting

jjs

Java IDL and RMI-IIOP

tnameserv
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/tnameserv.html#CACCHFHJ
Interface Definition Language (IDL).

idlj
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/idlj.html#BGBEEGCI
Generates Java bindings for a specified Interface Definition Language (IDL) file.

orbd
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/orbd.html#CIHCHGGA
Enables clients to locate and call persistent objects on servers in the CORBA environment.

servertool
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/servertool.html#BHBDJEAE
Provides an easy-to-use interface for developers to register, unregister, start up, and shut down a persistent server.

Internationalization

native2ascii
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/native2ascii.html#BGBBHBEH
Creates localizable applications by converting a file with characters in any supported character encoding to one with ASCII and/or Unicode escapes or vice versa.
将含有本地编码字符(既非 Latin1 又非 Unicode 字符)的文件转换为 Unicode 编码字符的文件。
native2ascii.exe 是 Java 的一个文件转码工具,是将特殊各异的内容转为用指定的编码标准文体形式统一的表现出来;

Web Services

schemagen

wsimport

wsgen

xjc

Unknow

javafxpackager

javapackager

java-rmi.cgi

javaws

jcontrol

jmc

jmc.ini

jrunscript

jvisualvm

参考

http://docs.oracle.com/javase/8/docs/technotes/tools/unix/
http://openjdk.java.net/tools/