问题描述
据我所知,Java中LISTEN / NOTIFY的JDBC驱动程序不支持真正的事件驱动通知。你必须经常轮询数据库以查看是否有新的通知。
From what I can tell, the JDBC drivers for LISTEN/NOTIFY in Java do NOT support true event-driven notifications. You have to poll the database every so often to see if there's a new notification.
我在Java中有哪些选项(可能是JDBC以外的东西?),如果有的话,以真正的事件驱动方式异步获取通知而不进行轮询?
What options do I have in Java (possibly something other than JDBC?), if any, to get notifications asynchronously in a true event-driven manner without polling?
推荐答案
使用pgjdbc-ng驱动程序。
Use the pgjdbc-ng driver.
它支持异步通知,无需轮询。我成功地使用了它。
It supports async notifications, without polling. I have used it successfully.
参见
Oleg有一个很好的例子答案
Oleg has a nice example answer as well
这篇关于如何使用Postgres数据库在Java中获得异步/事件驱动的LISTEN / NOTIFY支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!