0

I have a scenario where I check for a specific value in the Database every 10 seconds or so. And, if the value is YES, then I execute a bunch of shell scripts from a Java application.

Now, the value in database is only updated to YES once in a while depending on the user submitting a job on a web page. Therefore, running a while loop to check for this value in database seems to be a very bad design and I would like to implement a much cleaner approach using listeners (Observer design pattern).

How would such an implementation look like? Any examples I can follow to do this?

Pha3drus
  • 169
  • 1
  • 1
  • 10

2 Answers2

1

Yes there is much better job. So there is something called binlog reader in mysql. Thats how master and slave sync is done in mysql cluster database.

So either you write your own logic over https://github.com/shyiko/mysql-binlog-connector-java which gets all the chane event on table

or use https://github.com/zendesk/maxwell to read events from particular table and whenver any change in value is there check if it matches your condition and excute the script or java application on basis of that instead of running it as a cron.

Naruto
  • 4,221
  • 1
  • 21
  • 32
0

The general idea is to use DB triggers, register DB listener from Java side and be notified from DB side when some event has happened.

Pls review proposed solutions How to implement a db listener in Java

Community
  • 1
  • 1
Andriy Kryvtsun
  • 3,220
  • 3
  • 27
  • 41