0

I am looking for a way to specify the duration for a particular task to run - e.g. a particular file cleaner task may not run longer than 2 minutes. If it finishes under 2 minutes - great, but it should terminate after 2 minutes.

Does Quartz or any other library provide some effective way of doing so?

STW
  • 42,808
  • 17
  • 105
  • 157
rmoh21
  • 1,285
  • 6
  • 18
  • 33
  • By what means you expect the thread being terminated? The preferred way to end a thread is to end it peacefully by your program logic. e.g. a flag indicating we should jump out from loop, etc. Therefore it is almost impossible for anyone but yourself to "terminate" your thread. Have another thread, wait 2 min, and do the termination work. – Adrian Shum Oct 24 '12 at 03:30

1 Answers1

1

There is no such feature in quartz. You'll have to encapsulate the "timeout manager" in your job implementation.

You should detach the actual job implementation in a separate Task that is managed by the Quartz Job.

Take a look to this example: https://stackoverflow.com/a/2275596/1517816

Assume your QuartzJob is the Test class and move your business logic in the Task class.

Hope it helps

Community
  • 1
  • 1
poussma
  • 6,735
  • 3
  • 40
  • 65