如果由sheduled作业调用,Dropwizar不会看到标有@Timed批注的方法

时间:2019-04-01 12:25:32

标签: java spring-boot scheduled-tasks dropwizard

我有工作:

public class Jobber {
    @Timed(name = "my_timed")
    public void someJob(String symbol) {
        LOGGER.info("Started job");
        ...
    }
   public void startJob(String currency){
       threadPoolTaskScheduler.scheduleWithFixedDelay(
                () -> {
                  someJob(currency);                            
                }
                }, 5_000);

    }

和入门:

public class AppEvenListener implements ApplicationListener<ApplicationReadyEvent> {
    @Autowired
    private Jobber jobber;



    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        jobber.startJob("USD");

    }
}     

然后我启动了应用程序,发现dropwizard没有看到指标“ my_timed”为空:

count = 0
     mean rate = 0.00 calls/second
 1-minute rate = 0.00 calls/second
 5-minute rate = 0.00 calls/second
15-minute rate = 0.00 calls/second
           min = 0.00 milliseconds
           max = 0.00 milliseconds
          mean = 0.00 milliseconds
        stddev = 0.00 milliseconds
        median = 0.00 milliseconds
          75% <= 0.00 milliseconds
          95% <= 0.00 milliseconds
          98% <= 0.00 milliseconds
          99% <= 0.00 milliseconds
        99.9% <= 0.00 milliseconds

这让我感到惊讶,因为我能够在日志中找到很多Started job消息。

然后我尝试在main方法中这样做:

 Jobber jobber = applicationContext.getBean(Jobber.class);
        for (int i = 0; i < 1_000_000; i++) {
jobber            jobber.someJob("Ololo");
            Thread.sleep(10_000);
        }

然后,我开始看到“ my_timed”的度量标准不为空

所以我认为问题与后台线程有关。

我该如何解决?

PS 春季启动版本= 1.5

0 个答案:

没有答案