-2

I have an application that loads a job every 60 seconds. The job polls a table in the database(NoSQL) and If a new row exists it starts some processing in the DB.

Now in order to avoid SPOF I load another instance of the application and I would like to avoid contention over the indicating record.

What are the best practices to avoid contention between multi processes that poll the DB?
(Are there any known/recommended FW)

azurefrog
  • 10,785
  • 7
  • 42
  • 56
Bick
  • 17,833
  • 52
  • 146
  • 251
  • There could be multiple ways. When your process picks up the new row, it can record this fact in a way that any subsequent process is 'warned off' when it tries to say it is taking the row. For instance: write a record to some table to indicate it has taken the row, but only do so if no other process has taken it (and these two steps must be done in a way that your DBMS guarantees to be atomic). If the original record has some time-stamp field that you are allowed to update, that could be good enough. – Darius X. May 26 '15 at 21:16

1 Answers1

-2

I don't know any best practice to do this, but if I would be you I would create a main program called "Listener" to check the table, If a new record exists, this program will create another Thread which does whatever It has to do and dies when It finished. The Threads will be created dynamically and dies when the jobs are done, so in this way you can AVOID a SPOF.

Nico
  • 374
  • 2
  • 4
  • 17