java - Oracle 数据库更改通知仅每 15 分钟发送一次

标签 java oracle jdbc oracle11g eclipselink

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

        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 过程来接收通知,则通知是即时的。

我有哪些选项可以缩短间隔?我的目标是立即或每隔几秒。

最佳答案

提交的文档表明任何挂起的更改都应写入并提交到数据库。

所以我的猜测是,在调用 commit() 之前,还有一些不属于上述代码片段的内容占用了 15 分钟的时间。你可以测试一下。

一个潜在的解决方法(如果问题不是由于持久性框架级别的延迟造成的,而是被确定为 oracle 驱动程序或等效项的问题),则可以直接调用该过程。

关于java - Oracle 数据库更改通知仅每 15 分钟发送一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35020345/

相关文章:

java - Android {Java} 中的 XML 解析

java - Java中没有参数的for循环

java - 使用 JDBC 和 Oracle 序列化 ArrayList

java - JDBC 池连接验证

java - 在Spring JDBC中,如何在语句上设置RESULT SET HOLDABILITY?

java - 看不懂引用资料

java - Android 应用程序-将对象作为额外 Intent 传递与使用公共(public)成员变量

database - 甲骨文 12 PCTUSED & PCTFREE 和 INITRANS & MAXTRANS

.net - 如何使用 dbml 文件连接 oracle 数据库?

Python 连接 Oracle 数据库