Skip to content

Commit

Permalink
Make addCloseTask thread safe
Browse files Browse the repository at this point in the history
(cherry picked from commit 325de11)
  • Loading branch information
stuartwdouglas authored and gsmet committed Aug 3, 2021
1 parent c47aa86 commit aee7a90
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ public Class<?> visibleDefineClass(String name, byte[] b, int off, int len) thro
}

public void addCloseTask(Runnable task) {
closeTasks.add(task);
synchronized (closeTasks) {
closeTasks.add(task);
}
}

@Override
Expand All @@ -546,7 +548,11 @@ public void close() {
}
closed = true;
}
for (Runnable i : closeTasks) {
List<Runnable> tasks;
synchronized (closeTasks) {
tasks = new ArrayList<>(closeTasks);
}
for (Runnable i : tasks) {
try {
i.run();
} catch (Throwable t) {
Expand Down

0 comments on commit aee7a90

Please sign in to comment.