Java 11已于2018-09-25发布,作为一个LTS版本,值得重点关注。但从Java 8升级上来还是会碰到不少问题。

1、 project需要增加jaxb依赖,否则编译报错。

Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException

增加下面的依赖:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>

2、 某些GC废弃了,就不要用了。比如下面这个报错说明UseParNewGC这个新生代的GC就不支持了。

Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
Unrecognized VM option 'UseParNewGC'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

有哪些不支持,详细参考这里:JEP-214

Here is a detailed summary of the flags and flag combinations that will stop working:

DefNew + CMS       : -XX:-UseParNewGC -XX:+UseConcMarkSweepGC
ParNew + SerialOld : -XX:+UseParNewGC
ParNew + iCMS      : -Xincgc
ParNew + iCMS      : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC
DefNew + iCMS      : -XX:+CMSIncrementalMode -XX:+UseConcMarkSweepGC -XX:-UseParNewGC
CMS foreground     : -XX:+UseCMSCompactAtFullCollection
CMS foreground     : -XX:+CMSFullGCsBeforeCompaction
CMS foreground     : -XX:+UseCMSCollectionPassing

那么还有哪些可以用呢?当然是 G1 了,还有处于Experimental的ZGC,性能超强。看数据:

128G heap (Lower is better)

ZGC
                avg: 1.091ms (+/-0.215ms)
    95th percentile: 1.380ms
    99th percentile: 1.512ms
  99.9th percentile: 1.663ms
 99.99th percentile: 1.681ms
                max: 1.681ms

G1
                avg: 156.806ms (+/-71.126ms)
    95th percentile: 316.672ms
    99th percentile: 428.095ms
  99.9th percentile: 543.846ms
 99.99th percentile: 543.846ms
                max: 543.846ms

有关ZGC的介绍在JEP-333
源码下载browser->zip
Linux快速试验Wiki

3、 Android开发也需要注意,Gradle需要升级(4.7+),例如用4.10.2是可以的。

修改文件:$PROJECT\gradle\wrapper\gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

4、 Groovy动态脚本,有warning,换2.5.2/2.6.0-alpha-4/3.0.0-alpha-3都有。暂时忽略,等Groovy官网更新,或自己动手patch一下。

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/xxx/m2/repo/org/codehaus/groovy/groovy/3.0.0-alpha-3/groovy-3.0.0-alpha-3.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

5、 javascript动态脚本,由于Nashorn脚本引擎不计划维护了,也有warning提示。在jdk11当前Release中还是可以使用的,ECMAScript的新规范不会支持了。

Warning: Nashorn engine is planned to be removed from a future JDK release