diff --git a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java index 8a49bf7..172f58d 100644 --- a/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java +++ b/hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java @@ -61,6 +61,8 @@ private static final Logger LOG = LoggerFactory.getLogger(DbNotificationListener.class.getName()); private static CleanerThread cleaner = null; + private static final Object NOTIFICATION_TBL_LOCK = new Object(); + // This is the same object as super.conf, but it's convenient to keep a copy of it as a // HiveConf rather than a Configuration. private HiveConf hiveConf; @@ -252,7 +254,9 @@ private int now() { private void enqueue(NotificationEvent event) { if (rs != null) { - rs.addNotificationEvent(event); + synchronized(NOTIFICATION_TBL_LOCK) { + rs.addNotificationEvent(event); + } } else { LOG.warn("Dropping event " + event + " since notification is not running."); } @@ -274,7 +278,9 @@ private void enqueue(NotificationEvent event) { @Override public void run() { while (true) { - rs.cleanNotificationEvents(ttl); + synchronized(NOTIFICATION_TBL_LOCK) { + rs.cleanNotificationEvents(ttl); + } try { Thread.sleep(60000); } catch (InterruptedException e) {