【问题标题】:Oracle Database Change Notifications only sent every 15 minutesOracle 数据库更改通知仅每 15 分钟发送一次
【发布时间】:2016-05-03 09:36:07
【问题描述】:

我正在为 Oracle 数据库更改通知注册一个侦听器(使用 JPA 的 EclipseLink 实现、Oracle 11.2.0.3、Oracle JDBC 瘦驱动程序 11.2.0.4):

        entityManager.getTransaction().begin(); // otherwise we cannot unwrap the Connection from the entityManager
        Properties properties = new Properties();
        DatabaseChangeRegistration databaseChangeRegistration = ((OracleConnection)entityManager.unwrap(Connection.class)).registerDatabaseChangeNotification(properties);
        databaseChangeRegistration.addListener(this);

        //now you need to add whatever tables you want to monitor
        try (Statement stmt = entityManager.unwrap(Connection.class).createStatement()) {
            //associate the statement with the registration:
            ((OracleStatement) stmt).setDatabaseChangeRegistration(databaseChangeRegistration); //look up the documentation to this method [http://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleStatement.html#setDatabaseChangeRegistration_oracle_jdbc_dcn_DatabaseChangeRegistration_]
            try (ResultSet rs = stmt.executeQuery("SELECT * FROM MY_MONITORED_TABLE WHERE ROWNUM=1")) { //you have to execute the query to link it to the statement for it to be monitored
                while (rs.next()) {
                    //..do sth with the results if interested...
                }
            }
        }
        entityManager.getTransaction().commit();

我收到了通知,但所有通知都是每 15 分钟一次。 15 分钟是基于绝对时间,不管我什么时候开始听。发送通知的作业似乎只在服务器上以 15 分钟的固定间隔运行。

如果我直接在服务器上注册一个 PL/SQL 过程来接收通知,则通知是即时的。

我有什么选择来减少间隔?我的目标是瞬间或每隔几秒。

【问题讨论】:

  • 您在事务中执行此操作,是否是事务隔离阻止您在事务超时之前看到更改?您是否看过 EclipseLink 的 DCN 支持以及它如何添加侦听器:wiki.eclipse.org/EclipseLink/UserGuide/JPA/… 您最好使用 OracleChangeNotificationListener 子类在注册调用期间执行您想要的操作。
  • @Chris 如果不在使用普通 JDBC 的事务中发送,也会出现同样的问题。据我所知,EclipseLink 的 DCN 支持只针对缓存失效,不过我去看看。

标签: java oracle jdbc oracle11g eclipselink


【解决方案1】:

commit 的文档表明任何未决的更改都应该写入并提交到 db。

所以我的猜测是在调用 commit() 之前的 15 分钟内,还有一些不属于上述 sn-p 的东西。你可以测试一下。

一种可能的解决方法(如果问题不是由于持久性框架级别的延迟,而是被确定为 oracle-driver 或等效的问题),而是直接调用该过程。

【讨论】:

  • 同样的问题存在,如果注册是通过普通 JDBC 在事务之外完成的
  • 1.) 所以它在使用普通 jdbc 的事务中可以正常工作吗? 2.)但如果它在由容器管理的事务中,则不是这样? 3.)您是否尝试在有或没有事务的情况下从 JDBC 调用过程? 4.) 这是一个link,可能会有所帮助
  • 如果我不注册远程回调(它使用与服务器创建的我的机器的 TCP 连接)但对驻留在服务器本地的 PL/SQL 过程的回调,它工作正常。在后一种情况下,PL/SQL 过程会立即被调用,而在第一种情况下,最多需要 15 分钟才能发送回调。
猜你喜欢
  • 2021-04-05
  • 2019-04-23
  • 2015-09-13
  • 2012-04-19
  • 2013-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多