On March 21, Oracle announced the official release of Java 10. This is the first official release of Java after the big release cycle (see here), and it’s worth noting. You can download it immediately by clicking on the following address:
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Last September, Oracle changed the Java major release cycle from two to three years to a major release every six months. Java 8, Java 9, Java 10, Java 11…..
But unlike before, there is also a release number to indicate when the release is and whether it is LTS (long term support), such as Java 10 for 18.3. The following is an example:
/ JDK /bin$./ Java -version openJDK version "10" 2018-03-20 OpenJDK Runtime Environment 18.3 (build 10+46 64-bit Server VM 18.3 (Build 10+46, Mixed mode)
Copy the code
It is important to note that neither Java 9 nor Java 10 are LTS versions. Unlike past Major Java releases, these two only take about half a year to develop and maintain. The future Java 11, 18.9 LTS, will be the first LTS release since Java 8 (with long-term support from commercial companies such as Oracle).
This distribution model has been widely used, and a successful example is the Ubuntu Linux operating system, which has been supported for a long time with the April release as LTS in even-numbered years. Like the 14.04 LTS released in April 2014, Canonical and the community support it through 2019. Similarly, Node.js, the Linux kernel, and Firefox use similar distribution methods.
The future release cycle of Java will see a major release every six months and an intermediate feature release every quarter. This will allow for early incorporation of key features into the JDK, quick feedback from developers, and to avoid the embarrassment of having to delay the release of Java 9 twice.
The chart below shows the release and support cycle for future Java releases released by Oracle at JavaOne 2017.
With this release of Java 10, there are not many new features.
According to the official website, there are 12 JEPS (JDK Enhancement Proposal) with the following enhancements:
-
JEP286, VAR local variable type inference.
-
JEP296 simplifies the development and administration process by consolidating many JDK repositories previously managed with Mercurial into one repository.
-
JEP304, unified garbage collection interface.
-
JEP307, G1 garbage collector’s parallel full garbage collection implements parallelism to improve worst-case latency.
-
JEP310, Application Class Data (AppCDS) sharing, reduces memory footprint and startup time by sharing common class metadata across processes.
-
JEP312, ThreadLocal handshake interaction. Callbacks are performed on the thread without entering the global JVM Safepoint. Optimizations can stop only a single thread, rather than all or none at all.
-
JEP313, remove the javah tools shipped with the JDK. You can use javac -h instead.
-
JEP314, extension with additional Unicode language markup.
-
JEP317, which can allocate the heap memory footprint to a user specified spare memory device.
-
JEP317, using Graal’s Java-based compiler, can pre-compile Java code to native code to improve performance.
-
JEP318, which provides a default set of root certification authority certificates in OpenJDK. Open source the Java SE root certificate currently provided by Oracle to make OpenJDK easier for developers to use.
-
JEP322, a time-based release, the release cycle mentioned above. The version number is \$FEATURE.\$INTERIM.\$UPDATE.\$PATCH.
1. Var type inference.
This language feature has already been added to other languages (C#, JavaScript) and jre-based languages (Scala and Kotlin).
Considered early in the Java language, JEP286 proposal was formally submitted back in 2016. A public developer survey was held later, and the most popular recommendation was to go scala-like, “use val and VAR together” (about half); The second most common, at about a quarter, was “use var only”. After careful consideration, Oracle adopted the var keyword only.
With this feature, developers write code like this:
ArrayList<String> myList = new ArrayList<String>()
Copy the code
You can omit the previous type declaration and only need
var list = new ArrayList<String>()
Copy the code
The compiler will automatically infer the type of the list variable. It is also handy for chained expressions:
var stream = blocks.stream(); . int maxWeight = stream.filter(b -> b.getColor() == BLUE) .mapToInt(Block::getWeight) .max();
Copy the code
Developers do not need to declare and import the Stream type, only use Stream as an intermediate variable, and use the var keyword to improve development efficiency.
However, the use of VAR has many limitations, including that it cannot be used to infer method parameter types, can only be used in local variables, such as method blocks, and cannot be used to declare class variables, etc.
In addition, I personally believe that for developers, the obvious declaration of variable types provides more comprehensive language information and is a great help in understanding and maintaining code. Once VAR is widely used, developers reading tripartite code without IDE support can create a barrier to understanding the flow of the application. So I recommend writing variable types as clearly as possible, and legibility and maintainability of programs are sometimes more important.
2. Unified GC interface
In JDK10 code path for its/SRC/hotspot/share/gc /, various gc Shared rely on Shared code, gc including the default G1, there is also a classic Serial, Parallel, CMS gc implementation.
3. Application class data (AppCDS) sharing
The CDS feature is extended to include Application class-data Sharing (CDS) support from the Application Class based on the bootstrap Class.
The principle is as follows: the process of loading classes is recorded during startup and written into a text file. The startup text is directly read and loaded when it is started again. Imagine that the startup speed would increase if the application environment did not change significantly.
We can think of this as an operating system hibernation process, in which the current application environment is written to disk when the computer is turned off, and the environment can be quickly recovered when the computer is used again.
I did the following app startup experiment on my PC.
First, deploy the Wildfly 12 application server using the JDK10 preview as the Java environment. Another tool, CL4CDS [1], is needed to convert the log of the loaded class into a format that AppCDS can recognize.
A. Install wildfly and deploy an application with A full Angularjs, REST, and JPA application stack, start it three times after warm-up, and record the deployment time
Respectively 6716ms, 6702ms, 6613ms, the average time is 6677ms.
B. Add environment variables and start, and export startup logs
export PREPEND_JAVA_OPTS="-Xlog:class+load=debug:file=/tmp/wildfly.classtrace"
Copy the code
C. Use cl4CDS tool to generate CLS format that AppCDS can recognize
/jdk-10/bin/java -cp src/classes/ io.simonis.cl4cds /tmp/wildfly.classtrace /tmp/wildfly.cls
Copy the code
Open the file and you can see the following:
java/lang/Object id: 0x0000000100000eb0 java/io/Serializable id: 0x0000000100001090 java/lang/Comparable id: 0x0000000100001268 java/lang/CharSequence id: 0x0000000100001440 ...... org/hibernate/type/AssociationType id: 0x0000000100c61208 super: 0x0000000100000eb0 interfaces: 0x0000000100a00d10 source: / home/shihang/work/jboss/wildfly/dist/target/wildfly - 12.0.0. Final/modules/system/the layers/base/org/hibernate/main/hibernat E - core - 5.1.10. Final. Jar org/hibernate/type/AbstractType id: 0 x0000000100c613e0 super: 0 x0000000100000eb0 interfaces: 0x0000000100a00d10 source: / home/shihang/work/jboss/wildfly/dist/target/wildfly - 12.0.0. Final/modules/system/the layers/base/org/hibernate/main/hibernat E - core - 5.1.10. Final. Jar org/hibernate/type/AnyType id: 0 x0000000100c61820 super: 0 x0000000100c613e0 interfaces: 0x0000000100c61030 0x0000000100c61208 source: / home/shihang/work/jboss/wildfly/dist/target/wildfly - 12.0.0. Final/modules/system/the layers/base/org/hibernate/main/hibernat E - core - 5.1.10. Final. The jar...
Copy the code
This file is used to mark the loading information of the class.
D. Use environment variables to start Wildfly, simulate the startup process and export jSA files, which is to record the information of the startup class.
export PREPEND_JAVA_OPTS="-Xshare:dump -XX:+UseAppCDS -XX:SharedClassListFile=/tmp/wildfly.cls -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=/tmp/wildfly.jsa"
Copy the code
View the generated file information. The JSA file has a large size.
/opt/work/cl4cds$ ls -l /tmp/wildfly.*
-rw-rw-r-- 1 shihang shihang 8413843 Mar 20 11:07 /tmp/wildfly.classtrace
-rw-rw-r-- 1 shihang shihang 4132654 Mar 20 11:11 /tmp/wildfly.cls
-r--r--r-- 1 shihang shihang 177659904 Mar 20 11:13 /tmp/wildfly.jsa
Copy the code
E. Start the application server using the JSA file
export PREPEND_JAVA_OPTS="-Xshare:on -XX:+UseAppCDS -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=/tmp/wildfly.jsa"
Copy the code
The recorded time after the startup was 5535ms, 5333ms and 5225ms respectively, with an average of 5364ms, which was about 20% higher than the previous 6677ms.
This efficiency gain is valuable for cloud application deployment.
The above experimental methods refer to technical blog [2].
4. JEP314, extension with additional Unicode language markup.
JDK10 has more support for Unicode BCP 47, the IETF specification document for defining language sets. With the extension tag, you can more easily obtain the required locale.
For example, JDK10 adds a method,
java.time.format.DateTimeFormatter::localizedBy
Copy the code
In this way, you can use some numeric style, locale definition, or time zone to get the locale locale information needed for time information.
Note: link [3] shows all of the method level changes in JDK10.
5. View the current JDK management root certificate.
Since JDK9, add the -cacerts parameter to keytool to view the current root certificate managed by the JDK. In OpenJDK9, cacerts are empty, which gives developers a lot of change.
EP318 uses Oracle to open source Oracle JavaSE cacerts information, provides a default set of root certification authority certificates in OpenJDK, currently 80 records.
/jdk-10/bin$ ./keytool -list -cacerts
Enter keystore password:
Keystore type: JKS
Keystore provider: SUN
Your keystore contains 80 entries
verisignclass2g2ca [jdk], Dec 2, 2017, trustedCertEntry,
Certificate fingerprint (SHA-256): 3A:43:E2:20:FE:7F:3E:A9:65:3D:1E:21:74:2E:AC:2B:75:C2:0F:D8:98:03:05:BC:50:2C:AF:8C:2D:9B:41:A1
......
Copy the code
The next big release of Java will be Java 11, the LTS version after Java 8, which is expected to be released in September of this year. Currently there are only four Jeps, with more enhancements proposed to be added gradually.
This release will take full advantage of modularity, removing JavaEE and Corba from the current JDK and making it more compact.
While JDK9’s biggest strength is modularity, widespread adoption and adaptation in the Java industry is a process. There are currently some libraries that support modularity, such as Log4j2, but most are not yet supported.
We can expect modularity to become a long-term feature after the RELEASE of JDK11, with more and more libraries providing modularity support.
Java will continue to be the most suitable language and platform for application development, and the large community and wide range of developers will continue to encourage Java to continue to improve and improve in all areas of programming.
To quote the article author express thanks! The diagrams, data, and methods cited belong to the original author.
[1]: https://simonis.github.io/cl4cds/
[2]: https://marschall.github.io/2018/02/18/wildfly-appcds.html
[3]: https://gunnarmorling.github.io/jdk-api-diff/jdk9-jdk10-api-diff.html#java.time.format.DateTimeFormatter
Zhang Jianfeng, co-founder of Yongyuan Middleware, former member of JBoss application server core development team of Red Hat Company. He graduated from Beijing University of Posts and Telecommunications and Tsinghua University and worked for Kingsoft software, IONA Technology And Red Hat Software.
Familiar with JavaEE specifications; Open source technology enthusiasts, like to contact all kinds of open source projects, learning excellent and reference, think that reading good source code and reading a good book is as enjoyable; Rich practical experience and insights in distributed computing, enterprise application design, mobile industry application, DevOps and other technical fields; I am willing to think about the management thought behind the software and think that software technology is a way to achieve efficient management. I am willing to combine management and software development.