0

The normal way is calling database from java. But as per my scenario some third party application is doing inserts and my application is just reading. In that case is it possible to do something so that whenever there is new data or db data gets updated I want my java to get that data. i.e. any change in db would trigger my java class. By not running any process or threads i.e. like run a process every 2-5 mins to check db that would increase unnecessary load on server and also it wont be live that means anything comes to the db in mean time is missed.

Srinivas Gadilli
  • 342
  • 6
  • 25

2 Answers2

0

There might be other good solutions to this problem (see my comment), but one possible quick & dirty trick is to write an insert/update trigger that writes the new inserted/updated data to a file.

Now, in order to make things synchronous, you can make that 'file' a named pipe (a FIFO), providing that you run on a *nix system. In this way, you can have the Java code doing a blocking read on the pipe and, every time there is a new insert/update, the MySQL will write to the pipe (be careful to avoid EOFs) and the consumer (your Java code) will unblock itself, process the new data, and then block again, avoiding unnecessary load.

fanton
  • 720
  • 5
  • 19
-1

I think there would be no way to do that.

(And belows may not be an answer but a recommend.) It seems that java and other application connect DB simultaneiusly. I think the problem comes from here. 3rd party app should notify to my app .. and my app should insert to DB and do what I want. Then there will be no problem like this and more flexible work we can do. And more safe.. There may be some other reason... but I hope you to consider this also..

Gary Y Kim
  • 79
  • 4