作为最新版本的Java SE 13有哪些新特性?


Java SE 13于2019年9月17日正式发布,该版本主要包含5个新特性

JEP 350 Dynamic CDS Archiving
JEP 351 ZGC Uncommit Unused Memory
JEP 353 Reimplement the Legacy Socket API
JEP 354 Switch Expressions (Preview)
JEP 355 Text Blocks (Preview)

这几个新特性会带来什么样的改变呢?接下来我们一起学习一下这5个新特性。

JEP 350 Dynamic CDS Archiving

JPE 350 对appCDS进行性了扩展,允许在Java应用执行结束时动态归档类。归档类包括包括默认的基础层CDS(class data-sharing) 存档中不存在的所有已加载的应用程序类和类库。通过此仿瓷提高了AppCDS的可用性。

JEP 351 ZGC Uncommit Unused Memory

ZGC was enhanced to return unused heap memory to the operating system. This is useful for applications and environments where memory footprint is a concern.
This feature is enabled by default, but can be explicitly disabled using -XX:-ZUncommit. Furthermore, memory will not be uncommitted so that the heap size shrinks below the minimum heap size (-Xms). This means this feature will be implicitly disabled if the minimum heap size (-Xms) is configured to be equal to the maximum heap size (-Xmx).
An uncommit delay can be configured using -XX:ZUncommitDelay= (defaults to 300 seconds). This delay specifies for how long memory should have been unused before it’s eligible for uncommit.
For more details, see (JEP 351).

JEP 351对ZGC进行了增强,在以前的版本中,java GC之后并不会将系统内存释放给OS,因为每次释放都意味着重新调整jvm的内存大小,存在一定的消耗。随着软件的发展,我们发现在很多时候内存是比较昂贵的资源,所以将不用的内存释放回去给OS是非常有必要的。
此功能在默认情况下已开始,但可以通过-xx:-zuncommit参数禁用。
注意:如果最新内存参数设置比最大内存参数大,那么此功能将隐式禁用。

JEP 353 Reimplement the Legacy Socket API

The underlying implementation for the java.net.Socket and java.net.ServerSocket APIs has been replaced in this release. JEP 353 provides all the details on this change.
Every effort has been made to ensure that the new implementation is compatible with the old implementation but it is possible that there is existing code that depends on unspecified behavior in corner cases where the old and new implementations behave differently. The JDK continues to include the old implementation (known as “PlainSocketImpl” or the “plain” implementation) to allow such code continue to run. The old implementation is selected by running with the system property “jdk.net.usePlainSockteImpl” set, or set to the value “true”, i.e. run with -Djdk.net.usePlainSocketImpl or -Djdk.net.usePlainSocketImpl=true. The property can also be configured in the JDK network configuration file, located in ${java.home}/conf/net.properties. The old implementation, and the system property to select the old implementation, will be removed in a future release.

在这个版本中,将使用新的实现来代替java.net.socket和java.net.serversocket API的底层实现。
新版本中旧的API还未删除,可以通过配置系统属性"jdk.net.useplansocketimpl"来使用他们。但默认实现是最新版本的。

JEP 354 Switch Expressions (Preview)

Extend switch so it can be used as either a statement or an expression, and so that both forms can use either traditional case … : labels (with fall through) or new case … -> labels (with no fall through), with a further new statement for yielding a value from a switch expression. These changes will simplify everyday coding, and prepare the way for the use of pattern matching in switch. This is a preview language feature in JDK 13.

扩展开关,以便它可以用作语句或表达式,并且两种形式都可以使用传统的情况…:标签(带有贯穿线)或新案例…->标签(没有掉进去),还有一个新的语句,用于从开关表达式中产生值。这些变化将简化日常编码,并为在交换机中使用模式匹配做好准备。这是jdk 13中的一个预览语言特性。

JEP 355 Text Blocks (Preview)

Add text blocks to the Java language. A text block is a multi-line string literal that avoids the need for most escape sequences, automatically formats the string in a predictable way, and gives the developer control over format when desired. This is a preview language feature in JDK 13.

向Java语言添加文本块。文本块是一个多行字符串文本,它避免了大多数转义序列的需要,自动以可预测的方式格式化字符串,并在需要时让开发人员控制格式。这是jdk 13中的一个预览语言特性。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值