From 1fbaeaa767b0f0591fde17f4c90d2cd1d1f48a4a Mon Sep 17 00:00:00 2001 From: Dmitry Bushev Date: Sun, 20 Oct 2024 21:25:21 +0300 Subject: [PATCH] Unblock the hooks execution (#11359) close #11231 Changelog: - fix: do not block during the hooks execution --- .../execution/RuntimeExecutionHooks.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/engine/runtime-instrument-common/src/main/java/org/enso/interpreter/instrument/execution/RuntimeExecutionHooks.java b/engine/runtime-instrument-common/src/main/java/org/enso/interpreter/instrument/execution/RuntimeExecutionHooks.java index 7b54b18e905d..e0ed5d32be18 100644 --- a/engine/runtime-instrument-common/src/main/java/org/enso/interpreter/instrument/execution/RuntimeExecutionHooks.java +++ b/engine/runtime-instrument-common/src/main/java/org/enso/interpreter/instrument/execution/RuntimeExecutionHooks.java @@ -21,15 +21,21 @@ public void add(Runnable hook) { @Override public void run() { + Runnable[] hooksToRun; synchronized (hooks) { - for (Runnable hook : hooks) { - try { - hook.run(); - } catch (Exception e) { - logger.error("Failed to run execution hook.", e); + hooksToRun = hooks.toArray(new Runnable[0]); + } + + for (Runnable hook : hooksToRun) { + try { + hook.run(); + } catch (Exception e) { + logger.error("Failed to run execution hook.", e); + } finally { + synchronized (hooks) { + hooks.remove(hook); } } - hooks.clear(); } } }