• SpringBoot集成JMH


    第一步:添加依赖:

    <dependency>
    <groupId>org.openjdk.jmh</groupId>
    <artifactId>jmh-core</artifactId>
    <version>1.19</version>
    </dependency>
    <dependency>
    <groupId>org.openjdk.jmh</groupId>
    <artifactId>jmh-generator-annprocess</artifactId>
    <version>1.19</version>
    <scope>provided</scope>
    </dependency>

    第二步:创建类:
    /**
     * @desc:
     * @author: 毛会懂
     * @create: 2021-11-16 13:32:00
     **/
    @BenchmarkMode(Mode.AverageTime)
    @OutputTimeUnit(TimeUnit.MILLISECONDS)
    @Warmup(iterations = 5,time = 1,timeUnit = TimeUnit.SECONDS)
    @Measurement(iterations = 5,time = 1,timeUnit = TimeUnit.SECONDS)
    @Fork(1)
    @State(Scope.Benchmark)
    public class JMHFirstBenchmark {
    
        private BarrageService barrageService;
    
        @Setup(Level.Trial)
        public void setUp(){
            // 启动应用程序
            ConfigurableApplicationContext run = SpringApplication.run(xxxxApplicationBootstrap.class);
            // 从spring中拿Bean
            barrageService = run.getBean(BarrageService.class);
        }
    
        @Benchmark
        public void barrage(Blackhole bh1) throws InterruptedException {
            BarrageDTO barrage = new BarrageDTO();
            barrage.setActivityId(5368);
            ApiResult activityBarrages = barrageService.getActivityBarrages(barrage);
            bh1.consume(activityBarrages); // 防止jit陷阱
        }
    
        public static void main(String[] args) throws RunnerException {
            Options build = new OptionsBuilder().include(JMHFirstBenchmark.class.getSimpleName())
                    .build();
            new Runner(build).run();
        }
    }

    问题:jmh执行完, 应用还在启动中,会报错,但不影响jmh的使用。
  • 相关阅读:
    MVC添加
    bootstrap mvc
    mvc对象转成JSON格式
    乐观锁、悲观锁
    DOCKER上安装HASSIO
    Hass.io: add-on Samba
    Hass.io: add-on Configurator
    Lubuntu安装屏幕键盘onboard,使触摸屏可以登录和输入
    Dell Venue 8 Pro启动盘UEFI模式32位启动,备份系统
    屏幕录像软件Bandicam和oCam
  • 原文地址:https://www.cnblogs.com/maohuidong/p/15566091.html
Copyright © 2020-2023  润新知