Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the features of Java12

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "what are the characteristics of Java12", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the features of Java12"?

List of new features in JDK 12:

189:Shenandoah: a Low-Pause-Time Garbage Collector (Experimental)

230:Microbenchmark Suite

325:Switch Expressions (Preview)

334:JVM Constants API

340:One AArch74 Port, Not Two

341:Default CDS Archives

344:Abortable Mixed Collections for G1

346:Promptly Return Unused Committed Memory from G1

The first thing worth paying attention to is Switch Expressions, which is a feature for developers. We can quickly learn about it with specific code. Here is the switch syntax in the form of traditional statement:

Switch (day) {case MONDAY: case FRIDAY: case SUNDAY: System.out.println (6); break; case TUESDAY: System.out.println (7); break; case THURSDAY: case SATURDAY: System.out.println (8); break; case WEDNESDAY: System.out.println (9); break }

If you have coding experience, you must know that if a break is omitted in a switch statement, then the logic tends to go wrong, which is both tedious and error-prone. If replaced by an switch expression, the Pattern Matching mechanism can naturally guarantee that only a single path will be executed, as shown in the following code example:

Switch (day) {case MONDAY, FRIDAY, SUNDAY-> System.out.println (6); case TUESDAY-> System.out.println (7); case THURSDAY, SATURDAY-> System.out.println (8); case WEDNESDAY-> System.out.println (9);}

Further, the following expression provides us with an elegant way to express computational logic in a particular situation.

Int numLetters = switch (day) {case MONDAY, FRIDAY, SUNDAY-> 6; case TUESDAY-> 7; case THURSDAY, SATURDAY-> 8; case WEDNESDAY-> 9;}

Switch Expressions or related Pattern Matching features provide us with a trend of Java syntax evolution, which gradually liberates developers from complex and tedious low-level abstractions to a higher level and more elegant abstraction, which not only reduces the amount of code, but also avoids unexpected programming errors, so as to improve code quality and development efficiency.

Second, it is of great practical significance Shenandoah GC. It is a Pauseless GC implementation led by Redhat. Since it was developed around 2013, it has finally achieved important phased results. Like other Pauseless GC, the main goal of Shenandoah GC is that 99.9% of the pauses are less than 10ms, and the pauses are independent of heap size.

Perhaps there are few people who know about Shenandoah GC, and the louder voice in the industry is the ZGC that Oracle opened in JDK11, or the commercial version of Azul C4 (Continuously Concurrent Compacting Collector). However, the author believes that, at least for now, its practical significance is greater than the latter two, because:

The minimum threshold for using ZGC is to upgrade to JDK11, and for many teams, the jump in this version is not very low-cost, let alone it is not clear how ZGC actually performs in their own business scenarios.

And C4, after all, is the choice of local tycoons, the reality is, how many companies are not even willing to a dozens of yuan of License …

Shenandoah GC is released with a stable version of JDK8u, and as far as I know, some companies have been practicing in high real-time products such as HBase for a long time.

From the point of view of principle, we can refer to the official schematic diagram of the project, whose memory structure is very similar to that of G1, dividing the memory into region similar to a chessboard. The whole process is also similar to G1, the biggest difference is that it realizes the concurrent Evacuation link, and the introduction of Brooks Forwarding Pointer technology makes the object reference can still be accessed when GC moves objects.

The following is the performance of Shenandoah GC compared to other mainstream GC in jbb15 benchmark. GC pause is an order of magnitude higher than CMS and other options. For scenarios that are very sensitive to GC pause, the value is still very obvious, and can be significantly improved at the SLA level. Of course, this guarantee of low latency is also at the cost of consuming computing resources such as CPU, and the actual throughput performance is not very clear. It depends on the actual scenario requirements of the enterprise, and it is not a solution once and for all.

Other features, such as the two features related to G1, are effective improvements to G1 in specific scenarios, but they are not groundbreaking improvements and are no longer enumerated.

Compared with the long-term supported version (Long-Term-Support,LTS) of JDK11, JDK12 seems to have limited attention, and people are a little numb to the frequent rhythm of JDK, so

Does the non-LTS version of JDK12 have any production environment value?

Does Java's new release model achieve its goal of fast landing and iterating over new features?

Perhaps not many companies will choose JDK12 directly, but individual production practices are not far away. For example, my department found in the practice scenario that using JDK12's Abortable Mixed Collections for G1 solved the problem that HDFS's G1 Evacuation was too long in a particular scenario. Although the team finally chose to backport it to its own JDK11 version, it would not have come to a conclusion so quickly without a quick preview version of JDK12.

As for another issue, the author believes that it has been very successful so far, unlocking many shackles of the evolution of Java/JVM, and crucially, the power center of OpenJDK is being transferred to the development community and developers. In the new model, LTS can be used not only to meet the needs of long-term reliable support of enterprises, but also to meet the iterative demands of various developers for new features. You may have noticed that Switch Expressions is labeled Preview and Shenandoah GC is an Experimental feature, which is unrealistic in previous release cycles, because it is basically unrealistic to experiment with a feature with a minimum interval granularity of 2-3 years.

It can be expected that JDK8 will still be the mainstream for some time in the future. We have noticed that Amazon, Alibaba, Redhat, AdoptOpenJDK and other manufacturers or communities have released their own JDK8 and other products, and began to compete for the dominance of the long-term support version of JDK. The author thinks that this is a very good sign and reflects the increase of mainstream manufacturers' investment in Java.

Will it bring about the fragmentation of Java/JVM? Some will happen, but from the current cooperation model, OpenJDK is still the center of cooperation, leading the maintenance of the historical version of Java and the future evolution route.

At this point, I believe you have a deeper understanding of "what are the characteristics of Java12?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report