{"id":16995,"date":"2024-07-26T05:36:06","date_gmt":"2024-07-26T05:36:06","guid":{"rendered":"https:\/\/codener.com\/?p=16995"},"modified":"2024-07-26T05:50:14","modified_gmt":"2024-07-26T05:50:14","slug":"java-performance-startup-runtime-optimization-guide","status":"publish","type":"post","link":"https:\/\/codener.com\/java-performance-startup-runtime-optimization-guide\/","title":{"rendered":"Java Performance Practical Guide: Startup and Runtime Optimization Strategies"},"content":{"rendered":"\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>How long are you willing to wait? Five seconds? Ten? Maybe even twenty or more? Will you wait that long? No one enjoys dealing with an app that frequently irritates human psychology. Waiting five seconds for an application to load might not be so bad, but if it happens with every rotation of the clock&#8217;s dial from sunrise to sunset, it&#8217;s frustrating. Imagine starting your day using the app and then using it over 100 times before the day ends. Every second you wait adds up and costs money to your bank account.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Sounds like a nightmare, doesn\u2019t it? It becomes a reality if you deploy Java microservices to the cloud and you have to restart them frequently. It worsens the situation and incurs high costs, particularly if determined by the time you consume.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Well, it&#8217;s pretty easy to prefer a thoroughly optimized application with reliable speed, but what do you need to do? It requires efforts to fix the problem and calibrate application performance. <strong>&nbsp;<\/strong>This guide unveils practical strategies to optimize Java app startup and runtime performance. Discover how to improve speed and efficiency.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Why Does Software Performance Matter?<\/h2>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In the age of globalization, the world is characterized by fast-paced developments. Users demand an application that results in milliseconds. Even a fraction of a second delay can cause a loss of thousands of dollars in revenue and increase the bounce rate. Poorly performing software not only can be a reason to be frustrated but it will reduce your productivity and crash users&#8217; satisfaction.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>It is vital to maintain your software quality and meet users&#8217; demand, and for that Java performance tuning is crucial. Your digital economy relies on speedy and responsive software, hence to stay competitive it matters more than anything.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Therefore it is a critical matter to ensure software performance and prioritize a seamless <a href=\"https:\/\/codener.com\/the-7-essential-principles-of-user-experience-design\/\">user experience<\/a>. Let&#8217;s explore two strong reasons to know why you should prioritize it.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-columns dd is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column dg is-layout-flow wp-block-column-is-layout-flow\">\n<h3 class=\"wp-block-heading has-text-align-left yh\" style=\"font-size:14px\"><strong>User Experience and Retention<\/strong><\/h3>\n\n\n\n<span class=\"fd54 45\"> <p class=\"red-diamonds\">\t\t&#10209;<\/p><p class=\"fd533\"><strong> Users expect high-quality, user-friendly, and high-performance software for a delightful experience.\n<\/strong><\/p><\/span>\n<span class=\"fd54\"> <p class=\"red-diamonds\">\t&#10209;<\/p><p class=\"fd533\"><strong> User-friendly software with prompt, smooth responses motivates continued use and referrals.<\/strong><\/p><\/span>\n<span class=\"fd54\"> <p class=\"red-diamonds\">&#10209;<\/p><p class=\"fd533\"><strong> Poor-performing software causes frustration and leads users to avoid <br>it.<\/strong><\/p><\/span>\n<span class=\"fd54\"> <p class=\"red-diamonds\">&#10209;<\/p><p class=\"fd533\"><strong> Prioritizing user experience is essential for building product loyalty.\n<\/strong><\/p><\/span>\n<\/div>\n\n\n\n<div class=\"wp-block-column dg yu is-layout-flow wp-block-column-is-layout-flow\">\n<h3 class=\"wp-block-heading has-text-align-left yh\" style=\"font-size:14px\"><strong>Business Competitiveness<\/strong><\/h3>\n\n\n\n<span class=\"fd54 45\"> <p class=\"red-diamonds\">\t\t&#10209;<\/p><p class=\"fd533\"><strong> Business victory and competitiveness rely on application results in the digital world.<\/strong><\/p><\/span>\n<span class=\"fd54\"> <p class=\"red-diamonds\">&#10209;<\/p><p class=\"fd533\"><strong>High-performing software leads to better user satisfaction and a competitive edge.<\/strong><\/p><\/span>\n<span class=\"fd54\"> <p class=\"red-diamonds\">&#10209;<\/p><p class=\"fd533\"><strong> Useful applications lower operating costs, boost productivity and adapt to modifying user needs.\n<\/strong><\/p><\/span>\n<span class=\"fd54\"> <p class=\"red-diamonds\">&#10209;<\/p><p class=\"fd533\"><strong> Improved versions greatly influence customer acquisition and revenue in e-commerce and digital services, where speed and reliability are critical.\n<\/strong><\/p><\/span>\n<\/div>\n<\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Decoding Java&#8217;s Performance Puzzle<\/h2>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Probably it would not be wrong to say you aren\u2019t alone if you are struggling with slow startup times and large memory usage. Almost everyone encounters a comparable challenge when they work with Java, especially when it is in the context of microservices, serverless computing, and cloud deployment. The world of rapid responsiveness desires better transformations in Java to stay competitive.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>No doubt, Java, due to performing garbage collection and interpreting bytecode, maintained its reputation. In the last decade, the Java community worked hard to create efficient garbage collectors and developed advanced tools for Java memory optimization and management. Also encourages developers to write code for memory usage optimization. Overall, remarkable improvements have been made.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Java still has to go through an interpreter for each function, which is needed for its portability across various platforms. Nevertheless, this interpreter can delay the startup span of Java programs, specifically when it loads and initializes all the essential classes.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Further, because Java executes through an additional layer of abstraction corresponding to languages that interact more presently with the operating system, it can be intrinsically slower. Although some tools help to optimize Java bytecode, they may not be functional when dealing with numerous microservices that ought to work jointly.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>To address these problems, it has introduced technologies like AppCDS, native compilation, and CrAC. These technologies strive to enhance Java&#8217;s performance by either optimizing the startup procedure or bypassing the interpreter completely.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Understand the Key Points:<\/strong><\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<style>\n@media only screen and (max-width: 600px) {\nspan.fd5 {\n    display: flex;\n}\np.fd53 {\n    margin-left: 10px;\n}\n}\n<\/style>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\"><strong>Common issues:<\/strong> Slow JVM startup time and high memory usage.<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\"><strong>Core performance segments:<\/strong> Garbage collection and bytecode interpretation.<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\"><strong>Java community efforts:<\/strong> Efficient garbage collector, provoked code optimization, and progressive memory management mechanisms.\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\"><strong>Advanced technological innovations:<\/strong> Application Class Data Sharing (AppCDS), Coordinated Restore at Checkpoint (CrAC), and Ahead of Time (AOT) Compilation.\n<\/p><\/span>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Ways to Optimize Java Startup and Runtime Performance<\/h2>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>It is vital to optimize Java startup and runtime performance to deliver a responsive and efficient user experience. Java performance optimization for microservices should be your priority to minimize startup time and maximize runtime performance. Whether you\u2019re building a desktop application, a web application, or a microservice. To make it more versatile, it requires good tuning and systematic optimization.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>To ensure the modern commuting environment demands, explore these advanced techniques for optimization of Java startup and runtime performance:<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Application Class Data Sharing (AppCDS)<\/strong><\/li>\n<\/ol>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Class data sharing was introduced in 2004 but made voluntarily available in JDK 10 and further streamlined in JDK 13. CDS provides a technique to store loaded classes on the filesystem and enable them to be shared across JVM instances. AppCDS helps to improve Java startup time. It creates an outline of the classes used in the application.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>AppCDS improves Java startup and runtime performance by loading pre-processed class data from a shared archive, decreasing the time needed to initialize and load classes. This method lowers overall memory utilization, is especially useful in environments running multiple JVM instances, and assures more predictable and compatible class loading times across various JVM runs.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Key Optimizations:<\/strong><\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<span class=\"fd5\"><strong>&#8210;<p class=\"fd53\">Class Data Storage:<\/strong> Stores class metadata, including method bytecodes, in a shared archive, avoiding repeated parsing and linking across JVM instances.\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>&#8210;<p class=\"fd53\">Memory Mapping: <\/strong>Memory-maps the shared archive into the JVM\u2019s address space at startup, allowing direct access to class data and reducing disk load overhead.<\/p><\/span>\n\n<span class=\"fd5\"><strong>&#8210;<p class=\"fd53\">Class Verification and Linking: <\/strong>Pre-processes class verification and linking during archive creation, minimizing runtime workload and speeding up startup.<\/p><\/span>\n\n<span class=\"fd5\"><strong>&#8210;<p class=\"fd53\">Class Resolution: <\/strong>Ensures consistent class resolution across JVM instances by storing resolved class data in the shared archive for reuse.<\/p><\/span>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Advantages of AppCDS<\/strong><\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<style>\n@media only screen and (max-width: 600px) {\nspan.fd5 {\n    display: flex;\n}\np.fd53 {\n    margin-left: 10px;\n}\n}\n<\/style>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\">Reduce startup time\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\">Optimize memory footprint\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\">Efficient and improved runtime\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\">Streamline class loading consistency<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\">Optimize the use of system resource<\/p><\/span>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Steps to Implement AppCDS<\/strong><\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 1: Generate a Class List<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Generate a list of all the classes by running Java with a specific JVM option, during execution. This list includes both application-specific classes and library classes.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>COMMAND<\/span>\n     \n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>java -XX:DumpLoadedClassList=classes.lst -jar your-application.jar<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 2: Construct the shared archive<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Utilize the developed class list to construct a shared archive file. This file is usually named appcds.jsa and possesses pre-processed class data.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>COMMAND<\/span>\n     \n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>java -Xshare:dump -XX:SharedClassListFile=classes.lst -XX:SharedArchiveFile=\/path\/to\/appcds.jsa -cp \/path\/to\/classes\/*<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 3: Use the Shared Archive<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Configure the JVM to use the shared archive during startup. When the JVM starts, it loads the classes from the shared archive rather than loading and processing them one by one.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>COMMAND<\/span>\n     \n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>java -Xshare:on -XX:SharedArchiveFile=\/path\/to\/appcds.jsa -jar your-application.jar<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li><strong>Ahead of Time (AOT) Compilation with GraalVM<\/strong><\/li>\n<\/ol>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Primarily, Java depends heavily on one key optimization: the Just-In-Time (JIT) compiler. Generally, the JVM interprets every bytecode instruction into machine code each time it is performed, which can be slow. The JIT compiler improves this by transforming chunks of bytecode into machine code only when required, just before performance. This approach permits Java to maintain its platform-independent bytecode while running incredibly fast.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Unlike JIT, Ahead-of-Time (AOT) compilation improves performance by converting bytecode to machine code before the application runs, rather than during execution. It compiles the entire application into a standalone executable, just like any other native software, so it no longer needs a JVM to execute. Enable ahead-of-time compilation for Java with GraalVM to acquire this performance progress and guarantee more immediate application startup and execution.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Recasting Java Development with GraalVM Native Image:<\/strong><\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"419\" src=\"https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/AOT-Compilation-with-GraalVM-3-1024x419.png\" alt=\"\" class=\"wp-image-16997\" title=\"\" srcset=\"https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/AOT-Compilation-with-GraalVM-3-1024x419.png 1024w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/AOT-Compilation-with-GraalVM-3-300x123.png 300w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/AOT-Compilation-with-GraalVM-3-768x314.png 768w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/AOT-Compilation-with-GraalVM-3-1536x628.png 1536w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/AOT-Compilation-with-GraalVM-3.png 1800w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Benefits of GraalVM<\/strong><\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<style>\n@media only screen and (max-width: 600px) {\nspan.fd5 {\n    display: flex;\n}\np.fd53 {\n    margin-left: 10px;\n}\n}\n<\/style>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\">It analyzes the reachable code and removes the rest.\n\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\">By removing unused code, it reduces memory usage.\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\">By lessening the amount of unused code, it becomes more secure from potential vulnerabilities.\n<\/p><\/span>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><mark style=\"background-color:rgba(0, 0, 0, 0);color:#003b72\" class=\"has-inline-color\">How to use GraalVM for Ahead-of-Time (AOT) compilation?<\/mark><\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Here is a streamlined workflow for employing GraalVM for AOT compilation:<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 1: Install GraalVM and configure your environment.&nbsp;<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<style>\r\n  .K2_CBox{position:relative;background:#fff;width:100%;border-radius:6px;box-shadow: rgba(0, 0, 0, 0.15) 1.95px 1.95px 2.6px;padding:10px;margin:30px 0 30px}\r\n  .K2_CBox .CB_Heading{display:flex;justify-content:space-between;align-items:center;margin-bottom:15px}\r\n  .K2_CBox .CB_Heading span{margin:0;font-weight:700;font-family:inherit;font-size:1.1rem}\r\n  .K2_CBox .C_box_main{cursor:pointer;display:inline-flex;align-items:center;padding:12px;outline:0;border:0;border-radius:50%;background:#004cbd;transition:all .3s ease;-webkit-transition:all .3s ease}.K2_CBox .C_box_main:hover{opacity:.8}.K2_CBox .C_box_main .CBox_icn{flex-shrink:0;display:inline-block;width:18px;height:18px;background-image:url(\"data:image\/svg+xml,<svg xmlns='http:\/\/www.w3.org\/2000\/svg' fill='none' stroke='%23fefefe' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' viewBox='0 0 24 24'><rect x='5.54615' y='5.54615' width='16.45385' height='16.45385' rx='4'\/><path d='M171.33311,181.3216v-8.45385a4,4,0,0,1,4-4H183.787' transform='translate(-169.33311 -166.86775)'\/><\/svg>\");background-size:cover;background-repeat:no-repeat;background-position:center}\r\n  .K2_CBox .C_box_main.copied{background:#2dcda7}\r\n  .K2_CBox .C_box_main.copied .CBox_icn{background-image:url(\"data:image\/svg+xml,<svg xmlns='http:\/\/www.w3.org\/2000\/svg' fill='none' stroke='%23fefefe' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' viewBox='0 0 24 24'><path d='M22 11.07V12a10 10 0 1 1-5.93-9.14'\/><polyline points='23 3 12 14 9 11'\/><\/svg>\")}\r\n  .K2_CBox pre{margin:0;background:#f6f6f6;padding:15px;border-radius:5px;color:#08102b;font-size:.8rem;font-family:monospace;overflow:scroll;scroll-behavior:smooth;scroll-snap-type:x mandatory;-ms-overflow-style:none;-webkit-overflow-scrolling:touch; white-space: pre-wrap;}\r\n  .K2_CBox pre::before, .K2_CBox pre::after{content:''}\r\n  .dark-Mode .K2_CBox{background:#2d2d30}.dark-Mode .K2_CBox pre{background:#252526;color:#fffdfc}\r\n  .tNtf span{position:fixed;left:24px;bottom:-70px;display:inline-flex;align-items:center;text-align:center;justify-content:center;margin-bottom:20px;z-index:99981;background:#323232;color:rgba(255,255,255,.8);font-size:14px;font-family:inherit;border-radius:3px;padding:13px 24px; box-shadow:0 5px 35px rgba(149,157,165,.3);opacity:0;transition:all .1s ease;animation:slideinwards 2s ease forwards;-webkit-animation:slideinwards 2s ease forwards}\r\n  @media screen and (max-width:500px){.tNtf span{margin-bottom:20px;left:20px;right:20px;font-size:13px}}\r\n  @keyframes slideinwards{0%{opacity:0}20%{opacity:1;bottom:0}50%{opacity:1;bottom:0}80%{opacity:1;bottom:0}100%{opacity:0;bottom:-70px;visibility:hidden}}\r\n  @-webkit-keyframes slideinwards{0%{opacity:0}20%{opacity:1;bottom:0}50%{opacity:1;bottom:0}80%{opacity:1;bottom:0}100%{opacity:0;bottom:-70px;visibility:hidden}}\r\n  .darkMode .tNtf span{box-shadow:0 10px 40px rgba(0,0,0,.2)}\r\n  <\/style>\r\n<div id='toastNotif' class='tNtf'><\/div> \r\n<script>\/*<![CDATA[*\/ function copyC(e,t){var o=document.getElementById(e),n=document.getElementById(t),e=getSelection(),t=document.createRange();e.removeAllRanges(),t.selectNodeContents(n),e.addRange(t),document.execCommand(\"copy\"),e.removeAllRanges(),o.classList.add(\"copied\"),document.getElementById(\"toastNotif\").innerHTML=\"<span>Copied to Clipboard!<\/span>\",setTimeout(()=>{o.classList.remove(\"copied\")},3e3)} \/*]]>*\/<\/script>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>CODE<\/span>\n      <button id='copy1' class='C_box_main' onclick=\"copyC('copy1','code1')\">\n        <i class='CBox_icn'><\/i>\n      <\/button>\n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>gu install native-image<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 2: Compile your Java code as usual to develop bytecode.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>CODE<\/span>\n      <button id='copy1' class='C_box_main' onclick=\"copyC('copy1','code1')\">\n        <i class='CBox_icn'><\/i>\n      <\/button>\n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>javac MyApplication.java<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 3: Leverage GraalVM&#8217;s native-image mechanism to convert bytecode into a native executable.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>CODE<\/span>\n      <button id='copy1' class='C_box_main' onclick=\"copyC('copy1','code1')\">\n        <i class='CBox_icn'><\/i>\n      <\/button>\n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>native-image MyApplication<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 4: Execute the generated executable.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>CODE<\/span>\n      <button id='copy1' class='C_box_main' onclick=\"copyC('copy1','code1')\">\n        <i class='CBox_icn'><\/i>\n      <\/button>\n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>.\/myapplication<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\">\n<li><strong>Coordinated Restore at Checkpoint (CrAC)<\/strong><\/li>\n<\/ol>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Coordinated Restore at Checkpoint (CrAC) is also a JDK project that enables you to initiate a Java application profiling with a shorter span to the first transaction, integrated with less duration and fewer resources to acquire full code speed. CrAC enables Java programs to start up fast by taking a snapshot of the program after it has completely warmed up, then utilizing it to launch multiple JVM from this captured state and drive them to start faster.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Positioning CrAC is proximate to using AppCDS. First, you start a cold JVM with a distinctive parameter and then direct your program to warm it. Once it&#8217;s warmed up, pivot it off so CrAC can take a snapshot and preserve it on your computer.&nbsp;<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"583\" src=\"https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Coordinated-Restore-at-Checkpoint-1-1024x583.png\" alt=\"\" class=\"wp-image-17001\" title=\"\" srcset=\"https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Coordinated-Restore-at-Checkpoint-1-1024x583.png 1024w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Coordinated-Restore-at-Checkpoint-1-300x171.png 300w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Coordinated-Restore-at-Checkpoint-1-768x437.png 768w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Coordinated-Restore-at-Checkpoint-1-1536x874.png 1536w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Coordinated-Restore-at-Checkpoint-1.png 1789w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Let&#8217;s suppose you are running a server that manages a considerable number of SSL\/TLS handshakes. You want to acquire a snapshot of the cryptographic operations to ensure that your hardware accelerator is being utilized efficiently:<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 1: Start Monitoring<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>CODE<\/span>\n      <button id='copy1' class='C_box_main' onclick=\"copyC('copy1','code1')\">\n        <i class='CBox_icn'><\/i>\n      <\/button>\n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>crac-monitor --start --type tls_handshake --duration 60<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 2: Initiate Handshakes<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Direct a script that performs numerous SSL\/TLS handshakes for 60 seconds<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 3: Take Snapshot<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>CODE<\/span>\n      <button id='copy1' class='C_box_main' onclick=\"copyC('copy1','code1')\">\n        <i class='CBox_icn'><\/i>\n      <\/button>\n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>crac-snapshot --output \/path\/to\/snapshot.crac<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 4: Stop Monitoring<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>CODE<\/span>\n      <button id='copy1' class='C_box_main' onclick=\"copyC('copy1','code1')\">\n        <i class='CBox_icn'><\/i>\n      <\/button>\n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>crac-monitor --stop<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Step 5: Analyze Snapshot<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<!--[ Code Box 1 ]-->\n  <div class='K2_CBox'>\n    <div class='CB_Heading'>\n      <span>CODE<\/span>\n      <button id='copy1' class='C_box_main' onclick=\"copyC('copy1','code1')\">\n        <i class='CBox_icn'><\/i>\n      <\/button>\n    <\/div>\n\n    <!--Add Your Parse HTML code Here-->\n    <div id='code1'>\n        <pre>crac-analyze --input \/path\/to\/snapshot.crac --report \/path\/to\/report.html<\/pre>\n    <\/div>\n  <\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>After warming up your application and capturing a CrAC snapshot, you can launch multiple optimized JVMs quickly from this saved state for improved Java performance and monitoring.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"4\">\n<li><strong>Tune Garbage Collection (GC)<\/strong><\/li>\n<\/ol>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Garbage collection tuning plays a vital role in improving Java startup and runtime performance. It is the procedure by which the JVM automatically determines and reclaims memory that is no longer in use by the application. This process assures the best practices for Java memory management, helps to control memory leaks, and also optimizes performance.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Key Garbage Collectors<\/strong><\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<style>\n@media only screen and (max-width: 600px) {\nspan.fd5 {\n    display: flex;\n}\np.fd53 {\n    margin-left: 10px;\n}\n}\n<\/style>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\"> G1 Garbage Collector\n\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\"> Z Garbage Collector\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\"> Serial Garbage Collector\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\"> Parallel Garbage Collector\n<\/p><\/span>\n\n<span class=\"fd5\"><strong>\u2605<\/strong><p class=\"fd53\"> Concurrent Mark Sweep Garbage Collector\n<\/p><\/span>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The tuning process involves selecting the suitable garbage collector, adjusting heap size, and configuring different JVM choices to balance throughput, latency, and footprint.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Garbage-Collection-Tuning-Flow-1024x576.jpg\" alt=\"\" class=\"wp-image-17002\" title=\"\" srcset=\"https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Garbage-Collection-Tuning-Flow-1024x576.jpg 1024w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Garbage-Collection-Tuning-Flow-300x169.jpg 300w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Garbage-Collection-Tuning-Flow-768x432.jpg 768w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Garbage-Collection-Tuning-Flow-1536x864.jpg 1536w, https:\/\/codener.com\/wp-content\/uploads\/2024\/07\/Garbage-Collection-Tuning-Flow.jpg 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"5\">\n<li><strong>Use an Updated Version of the Java Application<\/strong><\/li>\n<\/ol>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Choosing the latest version of the Java development kit is an effective way to optimize your application startup and runtime performance. Each latest release of the JDK includes multiple performance enhancements, bug fixes, and security patches that can remarkably enhance the efficiency and soundness of your applications.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Final Thoughts<\/h2>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Optimizing Java startup and runtime performance is essential for delivering efficient and responsive applications in today&#8217;s fast-paced world. By leveraging advanced methods such as AppCDS, AOT compilation with GraalVM, CrAC, and garbage collection tuning, <a href=\"https:\/\/codener.com\/ecommerce-web-development-services\/\">developers<\/a> can significantly decrease load times and improve runtime efficiency. Plus, consistently updating the version ensures access to the latest performance.<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>These strategies collectively help to provide a seamless user experience, increase productivity, and maintain competitiveness in the market. So investing in performance optimization will be productive.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n  ","protected":false},"excerpt":{"rendered":"<p>How long are you willing to wait? Five seconds? Ten? Maybe even twenty or more? Will you wait that long? No one enjoys dealing with an app that frequently irritates human psychology. <\/p>\n","protected":false},"author":9,"featured_media":16996,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[68],"tags":[370],"class_list":["post-16995","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-informative","tag-java-performance"],"acf":[],"_links":{"self":[{"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/posts\/16995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/comments?post=16995"}],"version-history":[{"count":0,"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/posts\/16995\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/media\/16996"}],"wp:attachment":[{"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/media?parent=16995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/categories?post=16995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codener.com\/wp-json\/wp\/v2\/tags?post=16995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}