2

We use scheduled tasks in a Spring web application to send reminders, daily digests, etc.:

    <task:scheduled-tasks>
    <task:scheduled ref="fooService" method="bar" cron="0 0/5 * * * ?"/>
    </task:scheduled-tasks>

Each scheduled task invokes a given service method (fooService.bar() in the pseudocode above). I'd like to monitor how long each execution lasts. Some of these methods might take longer as load, data, or complexity increases. I can add logging statements to each service method (~10 now, but probably more in the future), or use aspects to put some stopwatch behavior around each method. But is there a more direct way to achieve this for all scheduled-tasks in spring?

Eric R. Rath
  • 1,939
  • 1
  • 14
  • 16

1 Answers1

1

You can use:

In all of the solutions above you need to somehow distinguish which methods you want to track. You can take all methods of some interface, all methods annotated with some annotation (including custom one), use method naming convention...

Of course you must choose a solution that best fits your needs as the ultimate goal is to have monitoring without adding any external code.

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • Thanks - I looked at org.springframework.aop.interceptor.CustomizableTraceInterceptor, and realized I wanted to add thresholds for logging at warn and error. I created my own MethodInterceptor implementation that met these needs, but your answer pointed me in the right direction, and answered the question I asked. – Eric R. Rath Jun 07 '12 at 22:30