2

I have a jvm process that wakes a thread every X minutes.
If a condition is true -> it starts a job (JobA).

Another jvm process does almost the same but if the condition is true -
it throws a message to a message broker which triggers the job in another server (JobB).

Now, to avoid SPOF problem I want to add another instance of this machine in my cloud.
But than I want ensure I run a single instance of a JobA each time.

What are my options?

Gergely Bacso
  • 14,243
  • 2
  • 44
  • 64
Bick
  • 17,833
  • 52
  • 146
  • 251

1 Answers1

1

There are a number of patterns to solve this common problem. You need to choose based on your exact situation and depending on which factor has more weight in your case (performance, correctness, fail-tolerance, misfires allowed or not, etc). The two solution-groups are:

  • The "Quartz" way: you can use a JDBCStore from the Quartz library which (partially) was designed for this very reason. It allows multiple nodes to communicate, and share state and workload between each other. This solution gives you a probably perfect solution at the cost of some extra coding and setting up a shared DB (9 tables I think) between the nodes.

  • Alternatively your nodes can take care of the distribution itself: locking on a resource (single record in a DB for example) can be enough to decide who is in charge for that iteration of the execution. Sharing previous states however will require a bit more work.

Gergely Bacso
  • 14,243
  • 2
  • 44
  • 64
  • I am using nosql, so Jdbc is not my way. I am currently locking a document but I thought maybe there is another recommendation (maybe a framework recommendation). – Bick Feb 10 '16 at 22:12
  • @rails JobStores exist for some of the nosql types, like redis-quartz or quartz-mongodb. What do you use? – Gergely Bacso Feb 10 '16 at 22:17