Table of Content
- upgrade build tools
- Add missing Java dependencies in jdk11
- Remove findbug and add Spotbugs
- Changes in GC options
- Fork-join Thread pool
- Class-Loader
- IDE-setup
for gradle,
minimum version should be 5.0
for maven,
upgrade maven compiler plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
// jdk 11 migration dependencies
implementation "javax.xml.bind:jaxb-api:2.3.1"
implementation "com.sun.xml.bind:jaxb-core:2.3.0.1"
implementation "com.sun.xml.bind:jaxb-impl:2.3.1"
implementation "com.sun.activation:javax.activation:1.2.0"
implementation("javax.annotation:javax.annotation-api:1.3.2")
// https://mvnrepository.com/artifact/org.ow2.asm/asm
compile group: 'org.ow2.asm', name: 'asm', version: '7.1'
compileOnly "com.github.spotbugs:spotbugs-annotations:$spotbugsannotationsVersion"
testCompile("javax.xml.ws:jaxws-api:2.3.1")
// end of jdk 11 migration dependencies
Refs: https://blog.joda.org/2018/09/time-to-look-beyond-oracles-jdk.html
https://adoptopenjdk.net/installation.html
https://stackoverflow.com/a/43574427/2987755
https://blog.codefx.org/java/java-11-migration-guide/
https://www.dariawan.com/tutorials/java/using-jaxb-java-11/
https://medium.com/criciumadev/its-time-migrating-to-java-11-5eb3868354f9
if you have spotbug config in different file other than build.gradle, then you need to specify
older way of specifying plugins(using buildscript) in gradle like
build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.spring.io/libs-release" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:2.0.0")
}
}
project.extensions.extraProperties.set('SpotBugsTask', com.github.spotbugs.SpotBugsTask)
apply from: file('gradle/spotbugs.gradle')
dependencies {
compile("org.ow2.asm:asm:${asmVersion}")
}
sprotbugs.gradle file
allprojects {
apply plugin: 'com.github.spotbugs'
apply plugin: 'jacoco'
apply plugin: "pmd"
// pmd, ./gradlew pmdMain
pmd {
toolVersion = '6.17.0'
ignoreFailures = true
pmdTest.enabled = true
}
//pmd task, wich will run along with ./gradlew clean build
tasks.withType(Pmd) {
reports {
xml.enabled = false
html.enabled = true
}
}
// To get report ./gradlew clean build; ./gradlew jacocoTestReport;
jacoco {
toolVersion = "0.8.4"
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.enabled true
}
}
spotbugs {
toolVersion = '3.1.12'
// continue build despite warnings
ignoreFailures = true
}
//To view spotbugs report in html format.
tasks.withType(SpotBugsTask) {
effort = 'max'
reports.xml.enabled = false
reports.html.enabled = true
maxHeapSize '2g'
}
}
change to java-11 java in console
Two flavours of open-jdk
AdoptOpenJdk(VM AdoptOpenJDK)
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.2+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.2+9, mixed mode)
Oracle's-openjdk(VM 18.9)
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
You can check release.txt
file at jdk home
Check avilability of flags in java 11 from here
-Xloggc:/myfolder/gc.log
is deprecated and needs to be -Xlog:gc:/myfolder/gc.log
instead
change following options from/to
-XX:+PrintGCDetails
-Xloggc:/tmp/application.gc.log
-XX:NumberOfGCLogFiles=5
-XX:GCLogFileSize=1M
changed to
-Xlog:gc*:file=/tmp/application.gc.log:uptime,level,tags:filecount=5,filesize=1M
#for safepoint
-Xlog:safepoint*:file=safepoints-%p-%t.log:tags,uptime,time,level:filecount=10,filesize=50m
#remove -XX:+UseGCLogFileRotation
#remove -XX:+PrintGCTimeStamps
Unrecognized in OpenJDK 11:
-d64
PrintGCTimeStamps
UseGCLogFileRotation
NumberOfGCLogFiles
GCLogFileSize
format:
-Xlog : <tags to log>[=<log level>] [: <output> [: <decorations> ]]
Ref
execute
java -Xlog:help
if you do not want to add which decorator, it is optional, and you can write it as
-Xlog:gc*:file=/tmp/application.gc.log::filecount=5,filesize=1M
jps
- Get the processid
jcmd <processid> VM.log what=gc*
That's it.
-Xlog Usage: -Xlog[:[what][:[output][:[decorators][:output-options]]]]
where 'what' is a combination of tags and levels of the form tag1[+tag2...][*][=level][,...]
Unless wildcard (*) is specified, only log messages tagged with exactly the tags specified will be matched.
Available log levels:
off, trace, debug, info, warning, error
Available log decorators:
time (t), utctime (utc), uptime (u), timemillis (tm), uptimemillis (um), timenanos (tn), uptimenanos (un), hostname (hn), pid (p), tid (ti), level (l), tags (tg)
Decorators can also be specified as 'none' for no decoration.
Available log tags:
add, age, alloc, aot, annotation, arguments, attach, barrier, biasedlocking, blocks, bot, breakpoint, cds, census, class,
classhisto, cleanup, codecache, compaction, compilation, constraints, constantpool, container, coops, cpu, cset, data,
datacreation, defaultmethods, dump, ergo, exceptions, exit, fingerprint, freelist, gc, handshake, hashtables, heap,
humongous, ihop, iklass, init, inlining, interpreter, itables, jit, jni, jvmti, liveness, load, loader, logging, mark,
marking, membername, memops, methodcomparator, metadata, metaspace, mmu, module, monitorinflation, monitormismatch,
nmethod, normalize, objecttagging, obsolete, oopmap, os, pagesize, patch, path, perf, phases, plab, promotion, preorder,
protectiondomain, ref, redefine, refine, region, remset, purge, resolve, safepoint, scavenge, scrub, smr, stacktrace,
stackwalk, start, startuptime, state, stats, stringdedup, stringtable, stackmap, subclass, survivor, sweep, table, task,
thread, tlab, time, timer, update, unload, unshareable, verification, verify, vmoperation, vmthread, vtables, workgang
Specifying 'all' instead of a tag combination matches all tag combinations.
Described tag combinations:
logging: Logging for the log framework itself
Available log outputs:
stdout, stderr, file=<filename>
Specifying %p and/or %t in the filename will expand to the JVM's PID and startup timestamp, respectively.
Some examples:
-Xlog
Log all messages using 'info' level to stdout with 'uptime', 'levels' and 'tags' decorations.
(Equivalent to -Xlog:all=info:stdout:uptime,levels,tags).
-Xlog:gc
Log messages tagged with 'gc' tag using 'info' level to stdout, with default decorations.
-Xlog:gc,safepoint
Log messages tagged either with 'gc' or 'safepoint' tags, both using 'info' level, to stdout, with default decorations.
(Messages tagged with both 'gc' and 'safepoint' will not be logged.)
-Xlog:gc+ref=debug
Log messages tagged with both 'gc' and 'ref' tags, using 'debug' level, to stdout, with default decorations.
(Messages tagged only with one of the two tags will not be logged.)
-Xlog:gc=debug:file=gc.txt:none
Log messages tagged with 'gc' tag using 'debug' level to file 'gc.txt' with no decorations.
-Xlog:gc=trace:file=gctrace.txt:uptimemillis,pids:filecount=5,filesize=1m
Log messages tagged with 'gc' tag using 'trace' level to a rotating fileset of 5 files of size 1MB,
using the base name 'gctrace.txt', with 'uptimemillis' and 'pid' decorations.
-Xlog:gc::uptime,tid
Log messages tagged with 'gc' tag using 'info' level to output 'stdout', using 'uptime' and 'tid' decorations.
-Xlog:gc*=info,safepoint*=off
Log messages tagged with at least 'gc' using 'info' level, but turn off logging of messages tagged with 'safepoint'.
(Messages tagged with both 'gc' and 'safepoint' will not be logged.)
-Xlog:disable -Xlog:safepoint=trace:safepointtrace.txt
Turn off all logging, including warnings and errors,
and then enable messages tagged with 'safepoint' using 'trace' level to file 'safepointtrace.txt'.
Finally,
-Dhazelcast.jmx=true -Dhazelcast.logging.type=slf4j -javaagent:jolokia-jvm-agent.jar
-Djavax.net.ssl.keyStore=keystore -Djavax.net.ssl.keyStorePassword=xxxx -Djavax.net.ssl.keyStoreType=PKCS12 -Djavax.net.ssl.trustStore=truststorefile -Djavax.net.ssl.trustStorePassword=xxxx -Djavax.net.ssl.trustStoreType=JKS
JAVA_OPTS=" -Djava.awt.headless=true -Djava.io.tmpdir=/tmp -Djava.net.preferIPv4Stack=true -Dspring.config.location=application.properties -Xms4198m -Xmx4198m -XX:NewRatio=3 -XX:+HeapDumpOnOutOfMemoryError -XX:MaxGCPauseMillis=200 -XX:+UseG1GC -XX:+UseStringDeduplication -XX:HeapDumpPath=/tmp/ -Xlog:gc*:file=/tmp/a.gc.log::filecount=5,filesize=1M -XX:+PrintCommandLineFlags"
Ref: https://www.oracle.com/technetwork/java/javase/9-notes-3745703.html#JDK-8172726
final ClassLoader parentThreadClassLoader = Thread.currentThread().getContextClassLoader();
final Runnable a = () -> {
Thread.currentThread().setContextClassLoader(parentThreadClassLoader);
}
forkJoinPool.submit(a);
Ref: https://stackoverflow.com/q/46694600/2987755
info: https://www.baeldung.com/java-classloaders
Ref: https://stackoverflow.com/a/60162761/2987755
Ref:
https://docs.microsoft.com/en-us/azure/java/jdk/transition-from-java-8-to-java-11
https://opennms.discourse.group/t/migration-of-jvm-settings-from-oracle-jdk-8-to-openjdk-11/365
https://stackoverflow.com/a/54145207/2987755
https://blog.gceasy.io/2017/10/17/43-gc-logging-flags-removed-in-java-9/
https://www.infoq.com/articles/upgrading-java-8-to-12/
https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-7744EF96-5899-4FB2-B34E-86D49B2E89B6
https://medium.com/criciumadev/its-time-migrating-to-java-11-5eb3868354f9
https://blog.joda.org/2018/09/from-java-8-to-java-11.html
https://www.infoq.com/news/2021/06/internals-encapsulated-jdk17/
Top comments (0)