Community Blog Java in Cloud-Native Era and How to Make Java Code More Efficient

Java in Cloud-Native Era and How to Make Java Code More Efficient

This article introduces how to reshape the java language on the cloud and includes a list of 50 efficient Java code samples.

In several respects, Java is the undisputed king of business applications. Developers, on the other hand, love and dislike it. Its diverse environment and comprehensive tool help boost application creation productivity significantly. In terms of runtime performance, however, Java is known as a "memory eater" and a "CPU shredder," and is therefore constantly threatened by modern and old languages such as Node.js, Python, and Golang.

Java's Transformation in the Cloud-Native Era

In the techn community, we often see that some people view Java technology unfavorably and think it cannot adapt to the development trend of cloud native. Let's put these views aside for the moment and think about the different requirements cloud-native imposes on application runtime.

1. Smaller size: Given the distributed architecture of microservices, a smaller size means lower download bandwidth and faster distribution and downloads.

2. Faster startup: For conventional stand-alone applications, startup speed is not a key metric compared with the runtime efficiency. This is because applications are infrequently restarted and released. However, for microservice-oriented applications that require fast iteration and horizontal scaling, faster startup means higher delivery efficiency and faster rollback. In particular, when you need to release an application with hundreds of replicas, a low startup speed could waste a great deal of time. For serverless applications, end-to-end cold startup speed is even more critical. Even if the underlying container technology allows resources to be prepared within milliseconds, if the application cannot be started within 500 milliseconds, the user will perceive the access latency.

3. Less resource utilization: Lower resource utilization when the application is running means higher deployment density and lower computing costs. In addition, during the startup of a Java virtual machine (JVM), a lot of CPU resources are consumed to compile bytecodes. Reducing resource consumption during startup can reduce resource contention, allowing developers to better guarantee the service-level agreement (SLA) of other applications.

4. Support for horizontal scaling: The memory management method of JVMs results in relatively low efficiency for large memory management. Generally, the performance of applications cannot be improved by configuring a larger heap size, and Java applications can rarely make good use of 16 GB memory or more. In addition, with the decline in memory costs and the popularity of virtualization, large memory ratios are becoming increasingly popular. Therefore, we usually adopt horizontal scaling and deploy multiple application replicas. Multiple replicas of one application may run on one computing node, improving the resource utilization.

Some people say that cloud-native is not intended for Java at all. However, the author thinks that they are wrong. He thinks that Java will remain a major player in the cloud-native era. Through a series of experiments, this article will provide a series of justifications for his opinion.

Reshaping the Java Language on the Cloud

Created some twenty years ago, Java is an object-oriented programming (OOP) language based on a large number of excellent enterprise-level frameworks. It provides stability and high performance under rigorous and long-term operating conditions. Language simplicity is important to ensure fast iteration and delivery on the cloud. This makes Java a seemingly an inappropriate language, being rather much a heavyweight. Yet, this language is still an important tool.

Alibaba's custom JDK, AJDK has evolved from a traditional managed runtime. AJDK will continue to improve the development experience for cloud applications and provide more possibilities for upper-layer applications through underlying innovation.

This article was prepared by Yu Lei, a technical expert from the Alibaba JVM team. In this article, Yu Lei describes how the JVM team deals with the challenge of serving a large number of complex services within Alibaba using Java.

50 Efficient Code Samples for Java Programming

The author is an IT engineer who has been working on the frontlines of programming for many years at Alibaba. He has an interest in programming techniques that solve practical problems.

There are only two qualities in the world: efficiency and inefficiency, and only two sorts of people: the efficient and the inefficient. -- Bernard Shaw

I would like to rephrase this quote of Bernard Shaw as follows: There are only two kinds of code: efficient code and inefficient code, and there are only two kinds of programmers in the world: programmers who write efficient code and programmers who write inefficient code. Every R&D team has to find a way to write efficient code. This article provides 50 efficient code samples based on the author's actual experience and extensive reading of reference materials. I hope this will enable all Java programmers to write efficient code.

Related Documentations

Install Alibaba Cloud SDK for Java

This topic describes how to install Alibaba Cloud SDK for Java by using Maven dependencies or by SDK tools. To install the SDK for any Alibaba Cloud product, you must install the Alibaba Cloud SDK for Java core library.

Quick start

This topic describes how to install and use Alibaba Cloud SDK. Alibaba Cloud SDK for Java takes the complexity out of coding and allows you to quickly access Alibaba Cloud services such as Elastic Compute Service (ECS), ApsaraDB for Relational Database Service (RDS), and CloudMonitor.

Are you eager to know the latest tech trends in Alibaba Cloud? Hear it from our top experts in our newly launched series, Tech Show!

0 0 0
Share on

Alibaba Clouder

2,600 posts | 750 followers

You may also like