1 Install Open JDK

Access OpenJDK repository, for example JDK 14 and download the selected architecture.

1.1 Install on MacOS

Unzip the file

Copy
$ gunzip openjdk-14.0.1_osx-x64_bin.tar.gz
jdk-14.0.1.jdk

Move JDK to /library/Java/JavaVirtualMachines

Copy
$ sudo mv jdk-14.0.1.jdk /library/Java/JavaVirtualMachines

Verify java is in place

Copy
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    14.0.1, x86_64:    "OpenJDK 14.0.1" /Library/Java/JavaVirtualMachines/jdk-14.0.1.jdk/Contents/Home    
    1.8.0_60, x86_64:  "Java SE 8"      /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home

1.2 Install on Linux (CentOS)

  • Visit JDK 14 releases page to download the latest archive.
  • Copy the URL for Linux
    Copy
    sudo yum -y install curl
    curl -O https://download.java.net/java/GA/jdk14.0.1/664493ef4a6946b186ff29eb326336a2/7/GPL/openjdk-14.0.1_linux-x64_bin.tar.gz
  • Extract the downloaded OpenJDK 14 archive file using tar command.
    Copy
    tar xvf openjdk-14.0.1_linux-x64_bin.tar.gz
  • Move the resulting folder to /opt directory.
    Copy
    mv jdk-14.0.1 /opt/
  • Configure Java environment:
    Copy
    cat > /etc/profile.d/jdk14.sh
    export JAVA_HOME=/opt/jdk-14.0.1
    export PATH=$PATH:$JAVA_HOME/bin
    ^D
  • Source your profile file and check java command
    Copy
    source /etc/profile.d/jdk14.sh
  • Confirm Java version.
    Copy
    $ java -version
    java -version
    openjdk version "14.0.1" 2020-04-14
    OpenJDK Runtime Environment (build 14.0.1+7)
    OpenJDK 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)

2 Java on MAC OS

You can determine Java versions installed on MAC by using:

Copy
/usr/libexec/java_home -V

2.1 Selecting java version

Switch to the desired version. For example, if you wish to switch to JDK 8, input the following line:

Copy
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

To handle multiple versions

Copy
alias j8="export JAVA_HOME=`/usr/libexec/java_home -v 1.8`; java -version"
alias j9="export JAVA_HOME=`/usr/libexec/java_home -v 9`; java -version"
alias j11="export JAVA_HOME=`/usr/libexec/java_home -v 11`; java -version"

3 Aquire a thread dump

A way to obtain the thread dump of a running java process to standard output.

jstack or kill -3 will generate dump in process standard output.

Copy
$ jps 
16437 Elasticsearch
16453 WebServer
16459 CeServer
16479 Jps
16431 WrapperSimpleApp
Copy
jcmd 16437 Thread.print
16437:
2019-11-26 23:26:27
Full thread dump OpenJDK 64-Bit Server VM (11.0.2+9 mixed mode):

Threads class SMR info:
_java_thread_list=0x00007ffc3c162d30, length=100, elements={
0x00007ffd10007800, 0x00007ffd1000f000, 0x00007ffd0900e800, 0x00007ffd09000800,
0x00007ffd09011800, 0x00007ffd09012000, 0x00007ffcc8004800, 0x00007ffca800c800,
0x00007ffcc83d5000, 0x00007ffc3a511000, 0x00007ffd087a8000, 0x00007ffd097f7000,
0x00007ffc39ba9000, 0x00007ffc3b452000, 0x00007ffc3ab97800, 0x00007ffd1032d000,
0x00007ffd0805b800, 0x00007ffc38f2a000, 0x00007ffc38f26000, 0x00007ffc39bc7800,
0x00007ffc38f27000, 0x00007ffc39bb6000, 0x00007ffc3b478000, 0x00007ffc39bbc000,
0x00007ffd0805a800, 0x00007ffd080e7000, 0x00007ffd087bb800, 0x00007ffc3b48c000,
0x00007ffc3b48d000, 0x00007ffc3b87a800, 0x00007ffc39c0e000, 0x00007ffc395ae000,
0x00007ffc3a573000, 0x00007ffc3ab74000, 0x00007ffc395a1800, 0x00007ffc3986a000,
0x00007ffc39bb4000, 0x00007ffc395a0800, 0x00007ffc39572800, 0x00007ffc3b872800,
0x00007ffc3a55d800, 0x00007ffc3b851000, 0x00007ffc3b48e000, 0x00007ffd0836c800,
0x00007ffc3b836000, 0x00007ffc6a008000, 0x00007ffc8883f800, 0x00007ffc3ab8b000,
0x00007ffc39573800, 0x00007ffc38000000, 0x00007ffc3b84d000, 0x00007ffd087ce000,
0x00007ffd083f1000, 0x00007ffc38af4000, 0x00007ffc3b48e800, 0x00007ffc3983d800,
0x00007ffc398d5000, 0x00007ffc3b0a4000, 0x00007ffd083fa000, 0x00007ffc38bbd000,
0x00007ffd0822f800, 0x00007ffc399eb800, 0x00007ffc3983e800, 0x00007ffc38bc5800,
0x00007ffd08027800, 0x00007ffc3a853800, 0x00007ffd087bc800, 0x00007ffd08232800,
0x00007ffc3b88d800, 0x00007ffc3abca800, 0x00007ffcb81d6000, 0x00007ffc3a2df000,
0x00007ffc3a18c800, 0x00007ffc88841800, 0x00007ffc69fc6800, 0x00007ffd0822e800,
0x00007ffd087a1000, 0x00007ffc3907d000, 0x00007ffd0879f800, 0x00007ffc3ce58800,
0x00007ffc3d3b0800, 0x00007ffc3e448800, 0x00007ffc3a188800, 0x00007ffc3e449000,
0x00007ffc3e436000, 0x00007ffd08160800, 0x00007ffc3a501800, 0x00007ffc3a7d7000,
0x00007ffc3a01a800, 0x00007ffc3a01b800, 0x00007ffc3a143800, 0x00007ffd08161800,
0x00007ffc3e434000, 0x00007ffc39840000, 0x00007ffd08067800, 0x00007ffc39bb9000,
0x00007ffc3c811800, 0x00007ffc3d3b3800, 0x00007ffc39593800, 0x00007ffc399f1000
}

"Reference Handler" #2 daemon prio=10 os_prio=31 cpu=2.94ms elapsed=525.81s tid=0x00007ffd10007800 nid=0x4f03 waiting on condition  [0x000070000c3bb000]
   java.lang.Thread.State: RUNNABLE
	at java.lang.ref.Reference.waitForReferencePendingList(java.base@11.0.2/Native Method)
	at java.lang.ref.Reference.processPendingReferences(java.base@11.0.2/Reference.java:241)
	at java.lang.ref.Reference$ReferenceHandler.run(java.base@11.0.2/Reference.java:213)

"Finalizer" #3 daemon prio=8 os_prio=31 cpu=0.65ms elapsed=525.81s tid=0x00007ffd1000f000 nid=0x3803 in Object.wait()  [0x000070000c4be000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(java.base@11.0.2/Native Method)
	- waiting on <0x00000007eaad7600> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(java.base@11.0.2/ReferenceQueue.java:155)
	- waiting to re-lock in wait() <0x00000007eaad7600> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(java.base@11.0.2/ReferenceQueue.java:176)
	at java.lang.ref.Finalizer$FinalizerThread.run(java.base@11.0.2/Finalizer.java:170)

"Signal Dispatcher" #4 daemon prio=9 os_prio=31 cpu=0.30ms elapsed=525.81s tid=0x00007ffd0900e800 nid=0x3e03 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

....