Improve error handling and logging in polling thread of OpenViduEventManager

v2compatibility
pabloFuente 2026-03-26 13:09:06 +01:00
parent 2d319ac131
commit 3f37b61b0d
1 changed files with 16 additions and 9 deletions

View File

@ -126,6 +126,7 @@ public class OpenViduEventManager {
}
this.pollingThread = new Thread(() -> {
try {
while (!this.isInterrupted.get()) {
this.getEventsFromBrowser();
this.emitEvents();
@ -135,7 +136,11 @@ public class OpenViduEventManager {
}
}
log.info("Polling thread is now interrupted!");
} catch (Exception e) {
log.error("Polling thread crashed: {}", e.getMessage());
} finally {
this.pollingLatch.countDown();
}
});
this.pollingThread.setUncaughtExceptionHandler(h);
this.pollingThread.start();
@ -261,7 +266,9 @@ public class OpenViduEventManager {
public void resetEventThread(boolean clearData) throws InterruptedException {
this.stopPolling(true, clearData);
this.pollingLatch.await();
if (!this.pollingLatch.await(10, TimeUnit.SECONDS)) {
log.warn("Polling thread did not stop within 10 seconds");
}
this.execService.shutdownNow();
this.execService.awaitTermination(10, TimeUnit.SECONDS);
this.execService = Executors.newCachedThreadPool();