spring boot 3.2.x 使用CDS加速启动

maven 配置 业务包和依赖包分离

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                    <layout>ZIP</layout>
                    <!--解决windows命令行窗口中文乱码-->
                    <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                    <!--这里是填写需要包含进去的jar,
                      必须项目中的某些模块,会经常变动,那么就应该将其坐标写进来
                      如果没有则nothing ,表示不打包依赖 -->
                    <includes>
                        <include>
                            <groupId>nothing</groupId>
                            <artifactId>nothing</artifactId>
                        </include>
                    </includes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <!--指定的依赖路径-->
                            <outputDirectory>
                                ${project.build.directory}/lib
                            </outputDirectory>
                            <excludeScope>provided</excludeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>cn.mhauto.cloud.platform.uaa.spring.UaaApplication</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

        </plugins>
    </build>

使用CDS加速

方式一使用spring的类加载器

  • 训练
java --enable-preview -XX:ArchiveClassesAtExit=./application.jsa -Dspring.context.exit=onRefresh -jar  target/xxx-0.0.1.jar
  • 启动
java  --enable-preview  -XX:SharedArchiveFile=application.jsa -jar target/xxx-0.0.1.jar

方式二,使用AppClassloder加载器

java --enable-preview -XX:ArchiveClassesAtExit=./application.jsa -Dspring.context.exit=onRefresh -cp mhauto-tenant-uaa-0.0.1.jar.original cn.mhauto.cloud.platform.uaa.spring.UaaApplication

java  --enable-preview  -XX:SharedArchiveFile=application.jsa -cp mhauto-tenant-uaa-0.0.1.jar.original cn.mhauto.cloud.platform.uaa.spring.UaaApplication

总结

  • 两种方式都能使用cds加速
  • 虽然使用的Spring 的类加载器, 但依然还有性能提升。
  • 提升启动速度大约45%
  • 启动时的cpu占用降低30%

相关推荐

  1. spring boot 3.2.x 使用CDS加速启动

    2024-07-11 12:20:03       31 阅读
  2. SpringBoot使用Jasypt加密

    2024-07-11 12:20:03       24 阅读
  3. 沁恒CH32V30X学习笔记10---pwm输出

    2024-07-11 12:20:03       46 阅读
  4. 沁恒CH32V30X学习笔记04--外部中断

    2024-07-11 12:20:03       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 12:20:03       102 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 12:20:03       109 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 12:20:03       91 阅读
  4. Python语言-面向对象

    2024-07-11 12:20:03       98 阅读

热门阅读

  1. 37.深度学习中的梯度下降法及其实现

    2024-07-11 12:20:03       28 阅读
  2. Spring Boot与Spring MVC的区别和联系

    2024-07-11 12:20:03       32 阅读
  3. 代码随想录-DAY⑥-哈希表——leetcode 383 | 454

    2024-07-11 12:20:03       27 阅读
  4. linux去掉行首的#字符

    2024-07-11 12:20:03       25 阅读
  5. 常见的负载均衡算法和实现方式

    2024-07-11 12:20:03       28 阅读
  6. Android焦点之Focused Window的更新(二)

    2024-07-11 12:20:03       24 阅读
  7. SpringBoot源码阅读(9)——转换服务

    2024-07-11 12:20:03       22 阅读
  8. C#中的Dictionary

    2024-07-11 12:20:03       26 阅读
  9. C语言标准库中的函数

    2024-07-11 12:20:03       31 阅读
  10. MVC分页

    MVC分页

    2024-07-11 12:20:03      32 阅读
  11. 整数 d → 字符 ‘d‘ 的转换代码为:d+‘0‘

    2024-07-11 12:20:03       26 阅读
  12. 进阶版智能家居系统Demo[C#]:整合AI和自动化

    2024-07-11 12:20:03       25 阅读
  13. 【C语言】C语言可以做什么?

    2024-07-11 12:20:03       26 阅读
  14. Windows图形界面(GUI)-SDK-C/C++ - 按钮(button)

    2024-07-11 12:20:03       28 阅读