开发者

Multithreading on a database using oracle and mysql

开发者 https://www.devze.com 2023-04-02 11:40 出处:网络
Does anyone have a code sample of开发者_开发百科 a multithreading case that has about 25 threads that monitor a specific table in the database for a change then execute a process based on that change?

Does anyone have a code sample of开发者_开发百科 a multithreading case that has about 25 threads that monitor a specific table in the database for a change then execute a process based on that change?


If you just want to be notified in the client application that something has changed in the database and you need to react on that in the application itself (so that triggers are not an option) you can use Oracle's change notification.

In order to do that, you register a listener with the JDBC driver specifying the "result set" that should be monitored. That listener will be called whenever something changes in the database.

For details on how this works, see the manual:

http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/dbmgmnt.htm#CHDEJECF


If you want to monitor the table (in the database) and make changes also in the database, then you should really consider Triggers.

Simply, Triggers are kind of procedures that run automatically BEFORE or AFTER changes on a table. You can monitor UPDATE, INSERT or DELETE transactions and then make your action.

Here is Simple tutorial on Oracle Triggers


Try directly using a Database Trigger instead.

Check this question about getting events in java from Database

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号