JDK17详解

1. JDK17概述

国内一直流行一句话,他发任他发,我用Java8。目前也有一些厂商升级到jdk17,我理解升级到jdk17基于以下几点考虑。
1.对jdk17有特殊性能场景考虑。
2.对jdk17新特性有充分的使用场景。
3.对jdk17开源协议是否收费需要考虑。
4.新版本的springboot需要jdk17支持。
5.老版本的jdk维护时间到了。
6.项目jdk升级成本。

接下来展开讲讲各个考虑点。

2. JDK各个版本支持

Oracle Java SE Support Roadmap

在这里插入图片描述
上述可以看出。
长期支持版本LTS:jdk8,11,17,21,25.
jdk8发布与2014年,最长支持到2030年,这个还是很长的。
jdk17发布于2021年,最长支持到2029年。

3. JDK17收费情况

JDK17之后的版本可以免费分发和商用,但是仅有3年时间,3年后无法免费商用。JDK17确实可以免费商用,时间截止到2024年9月,共计3年。

注意,大家需要知道的是OracleJDK17的免费和OracleJDK 8u221之前的免费存在巨大的区别:OracleJDK 8u221之前版本是可以无限期免费使用的,而OracleJDK17只有3年的免费期,期限一过,再使用就必须商业收费(前提是Oracle保持承诺,所有LTS都免费3年)。

4. JDK17性能分析

How much faster is Java 17?
文章从性能等对比分析11,16,17,说明为什么选择jdk17,总结如下。

全文总结
本文主要围绕 Java 17 的性能测试展开,对比了 Java 17 与 Java 11、Java 16 在不同垃圾回收器(G1GC 和 ParallelGC)下的性能表现。

重要亮点

  • Java 17 与其他版本对比:Java 17 在 G1GC 下,平均比 Java 11 快 8.66%,比 Java 16 快 2.41%;在 ParallelGC 下,比 Java 11 快 6.54%,比 Java 16 快 0.37%。
  • 不同垃圾回收器性能:ParallelGC 比 G1GC 快,在 Java 17 中,ParallelGC 比 G1GC 快 16.39%。
  • 测试环境与方法:硬件配置为特定的英特尔处理器和内存,使用特定的 JDK 版本和 JVM 选项,每个运行解决 11 个规划问题,每个问题运行 5 分钟,进行 3 次运行取平均值。
  • 测试结果的可靠性:机器重新分配的数字在相同 JDK 和 GC 的不同运行中波动较大,其他数字相对更可靠。
  • 结论:对于 OptaPlanner 用例,Java 17 的性能提升值得升级,且 ParallelGC 仍是这些用例中最快的垃圾回收器。

5. JDK17使用分析

snyk关于JVM生态2018年与2020年的调查报告。
https://res.cloudinary.com/snyk/image/upload/v1539774333/blog/jvm-ecosystem-report-2018.pdf

5. JDK17协议分析

JDK17许可协议(NFTC):
https://www.oracle.com/downloads/licenses/no-fee-license.html
协议条款太多了,总结下Oracle No-Fee Terms and Conditions (NFTC)协议。

License Rights and Restrictions 许可权利和限制

Oracle grants to You, as a recipient of this Program, subject to the conditions stated herein, a nonexclusive, nontransferable, limited license to:
Oracle向作为本计划接受者的您授予以下非排他性、不可转让的有限许可:

(a) internally use the unmodified Programs for the purposes of developing, testing, prototyping and demonstrating your applications, and running the Program for Your own personal use or internal business operations; and
(a)在内部将未经修改的程序用于开发、测试、原型设计和演示您的应用程序,以及为您自己的个人使用或内部商业运营运行该程序;和

(b) redistribute the unmodified Program and Program Documentation, under the terms of this License, provided that You do not charge Your licensees any fees associated with such distribution or use of the Program, including, without limitation, fees for products that include or are bundled with a copy of the Program or for services that involve the use of the distributed Program.
(b)根据本许可条款重新分发未经修改的程序和程序文档,前提是您不向您的被许可人收取与此类分发或使用程序相关的任何费用,包括但不限于包含或捆绑程序副本的产品或涉及使用分发程序的服务的费用。

You may make copies of the Programs to the extent reasonably necessary for exercising the license rights granted herein and for backup purposes. You are granted the right to use the Programs to provide third party training in the use of the Programs and associated Separately Licensed Technology only if there is express authorization of such use by Oracle on the Program's download page or in the Program Documentation.
您可以在行使此处授予的许可权利和备份目的合理必要的范围内复制程序。只有在Oracle在程序下载页面或程序文档中明确授权此类使用的情况下,您才有权使用程序来提供有关使用程序和相关单独许可技术的第三方培训。

Your license is contingent on compliance with the following conditions:
您的许可证取决于是否符合以下条件:

- You do not remove markings or notices of either Oracle's or a licensor's proprietary rights from the Programs or Program Documentation;
-您不能从程序或程序文档中删除Oracle或版权方专有权利的标记或通知;

- You comply with all U.S. and applicable export control and economic sanctions laws and regulations that govern Your use of the Programs (including technical data);
-您遵守管理您使用程序(包括技术数据)的所有美国和适用的出口管制和经济制裁法律法规;

- You do not cause or permit reverse engineering, disassembly or decompilation of the Programs (except as allowed by law) by You nor allow an associated party to do so.
-您不会导致或允许您或关联方对程序进行逆向工程、反汇编或反编译(法律允许的除外)。

For clarity, any source code that may be included in the distribution with the Programs is provided solely for reference purposes and may not be modified, unless such source code is under Separate Terms permitting modification.
为清楚起见,任何可能包含在程序分发中的源代码仅供参考,不得修改,除非此类源代码根据单独条款允许修改。

JDK17下载说明:
https://www.oracle.com/java/technologies/downloads/#java17
在这里插入图片描述
This is the last planned update of JDK 17 under the NFTC. Updates after September 2024 will be licensed under the Java SE OTN License (OTN) and production use beyond the limited free grants of the OTN license will require a fee.
这是JDK 17 在 NFTC 下的最后一次计划更新。2024 年 9 月之后的更新将根据Java SE OTN 许可证(OTN)获得许可,并且超出 OTN 许可证有限免费授权的生产使用需要付费。

确实可以免费商用,时间截止到2024年9月,共计3年。完整的许可协议在这里(),我把权利和义务放到附录1。里面说的比较清楚,在符合美国进出口限制的情况下,开发者既可以在内部使用JDK17,也可以发布给客户使用。需要指出这个许可协议是通用的,并不针对JDK17,只有在JDK17的下载页中给出了说明(https://www.oracle.com/java/technologies/downloads/)

6. JDK对springboot支持

https://docs.spring.io/spring-boot/docs/3.0.13/reference/htmlsingle/
Installing Spring Boot -3.0.13 需要jdk17或者更高的版本。

Spring Boot can be used with “classic” Java development tools or installed as a command line tool. Either way, you need Java SDK v17 or higher. Before you begin, you should check your current Java installation by using the following command

7. JDK17的14个新特性

jdk17 Features: https://openjdk.org/projects/jdk/17/
jdk17具体使用方式:https://blog.jetbrains.com/idea/2021/09/java-17-and-intellij-idea/

特性说明
306:Restore Always-Strict Floating-Point Semantics恢复始终执行严格模式的浮点定义
356:Enhanced Pseudo-Random Number Generators增强型伪随机数生成器
382:New macOS Rendering Pipeline新的 macOS 渲染管道
391:macOS/AArch64 PortmacOS AArch64 端口
398:Deprecate the Applet API for Removal弃用 Applet API
403:Strongly Encapsulate JDK InternalsJDK 内部强封装
406:Pattern Matching for switch (Preview)为 switch 支持模式匹配
407:Remove RMI Activation移除 RMI 激活
409:Sealed Classes密封类
410:Remove the Experimental AOT and JIT Compiler移除实验性的 AOT 和 JIT 编译器
411:Deprecate the Security Manager for Removal弃用安全管理器
412:Foreign Function & Memory API (Incubator)外部函数和内存 API(孵化中)
414:Vector API (Second Incubator)矢量 API(二次孵化中)
415:Context-Specific Deserialization Filters上下文特定反序列化过滤器
在Linux系统上安装JDK 17的命令如下: 1. 首先,创建一个用于安装JDK 17的目录,例如 `/home/jdk17`。你可以使用以下命令创建目录: ``` mkdir /home/jdk17 ``` 2. 下载JDK 17安装包。你可以使用以下命令从Oracle官方网站下载: ``` wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz -P /home/jdk17/ ``` 或者,如果你无法访问Oracle官方网站,你可以使用以下命令从另一个可靠的下载源下载: ``` wget http://49.232.8.65/jdk/jdk17/jdk-17_linux-x64_bin.tar.gz -P /home/jdk17/ ``` 3. 解压缩安装包。使用以下命令解压缩下载的安装包: ``` tar -zxvf /home/jdk17/jdk-17_linux-x64_bin.tar.gz -C /home/jdk17/ ``` 4. 配置环境变量。编辑你的 `~/.bashrc` 或 `~/.bash_profile` 文件,并将以下行添加到文件末尾: ``` export JAVA_HOME=/home/jdk17/jdk-17 export PATH=$JAVA_HOME/bin:$PATH ``` 5. 使环境变量生效。使用以下命令使环境变量生效: ``` source ~/.bashrc ``` 或 ``` source ~/.bash_profile ``` 6. 验证安装。运行以下命令验证JDK 17是否成功安装: ``` java -version ``` 你应该能够看到类似以下输出的版本信息: ``` java version "17" 2021-09-14 LTS Java(TM) SE Runtime Environment (build 17+35-LTS-2724) Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing) ``` 这样,你就成功在Linux系统上安装了JDK 17并配置了相关的环境变量。现在你可以编写并执行HelloWorld程序来测试安装是否成功。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值