1

I have some code execution which will scheduled many jobs at different date-time. So overall I will have lot of jobs to run at specific date-time. I know that there is Spring Scheduler which will execute a job at some time period, but it does not schedule a job dynamically. I can use ActiveMQ with timed delivery or Quartz for my purpose but looking for a little suggestion. Shall I use Quartz or ActiveMQ timed/delayed delivery or something else.

There is another alternative as well in Executor service with timed execution, but if application restarts then the job will be gone I believe. Any help will be appreciated.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
ritesh malav
  • 11
  • 1
  • 6

2 Answers2

0

You can start by using a cron-expression in order to cover the case when your application will restart. The cron-expression can be stored in the properties file. Also, when your application will be scheduled, you can restart or reschedule your job programatically by creating a new job instance with another cron-expression for example.

Dina Bogdan
  • 4,345
  • 5
  • 27
  • 56
  • Yes, can do that but that case my code will end up maintaining lot of things for me. Instead i was leaning more towards the Active-MQ solution where i will be the producer and i will be the consumer. While pushing the message in Active-MQ i will set the time when it shall be consumed and i won't have to maintain much on my code side. But i am not really sure if that is a scalable solution. – ritesh malav May 12 '19 at 12:55
  • It can be a possible solution, but you will introduce one more component into your system. You should consider if you can mantain the ActiveMQ and here I'm speaking about infrastructure requirements at first. – Dina Bogdan May 12 '19 at 12:57
  • If i can get more inputs towards the Active-MQ solution that will be good. – ritesh malav May 12 '19 at 12:57
  • 1
    Well deploying an Active-MQ component in AWS is not that big of a deal and i can always write producer and consumer for it. But it's just that in this scenario i won't have to maintain anything on database side like quartz and do more queries like spring scheduler. – ritesh malav May 12 '19 at 12:59
  • Well , if you will deploy in AWS and you can pay for the usage of ActiveMQ than it seems that it is a right choice. IMHO go on with this solution. – Dina Bogdan May 12 '19 at 13:00
0

While you can schedule message delivery in ActiveMQ it wasn't designed to be used as a job scheduler whereas that's exactly what Quartz was designed for.

In one of your comments you talked about wanting a "scalable solution" and ActiveMQ won't scale well with a huge number of scheduled jobs because the more messages which accumulate in the queues the worse it will perform since it will ultimately have to page those messages to disk rather than keeping them in memory. ActiveMQ, like most message brokers, was meant to hold messages for a relatively short amount of time before they are consumed. It's much different than a database which is better suited for this use-case. Quartz should scale better than ActiveMQ for a large number of jobs for this reason.

Also, the complexity of the jobs you can configure in Quartz is greater. If you go with ActiveMQ and you eventually need more functionality than it supports then that complexity will be pushed down into your application code. However, there's a fair chance could simply do what you want with Quartz since it was designed as a job scheduler.

Lastly, a database is more straight-forward to maintain than a message broker in my opinion and a database is also easy to provision in most cloud providers. I'd recommend you go with Quartz.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • I understand that Active-MQ was not developed for scheduling purpose whereas quartz had the exact motivation behind it. My only reason of going with Active-MQ is that code maintenance will be much less, since we already know that this queueing system already supports billions of message transfers then why not use for delayed messages. I will definitely checkout Quartz but is there some other alternate in build sort of in spring or something with less maintainability. Please suggest. – ritesh malav May 12 '19 at 15:57