首页 > 解决方案 > 如何对 Spring @Scheduled 任务进行性能和负载测试

问题描述

如果可能,我想使用 Apache JMeter 为 Spring @Scheduled 任务运行性能和负载测试。

  1. 它支持这个吗?
  2. 我怎样才能实现它?

我正在使用 Spring 5(非启动)和 JMeter 5.4.1

谢谢

编辑1:我的计划任务配置如下

package com.mypackage.impl;

import com.mypackage.service.NotificationBatchService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class NotificationBatchServiceImpl implements NotificationBatchService {

    @Override
    @Scheduled(cron = "0 0 */2 * * *")
    public void synchronizeNotificationUploadDocument() {
        // database transactions
        // HTTP requests
    }
}

标签: javaspringspring-mvcjmeterperformance-testing

解决方案


您应该将方法内的代码提取synchronizeNotificationUploadDocument到服务中,然后对该服务进行负载测试。


推荐阅读