Skip to content

Commit

Permalink
Sync when destroy (apache#11783)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ authored Mar 10, 2023
1 parent d0a1bd0 commit ba14a20
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,23 @@ protected void initialize() {
}

public void destroy() {
if (destroyed.compareAndSet(false, true)) {
try {
onDestroy();
HashSet<ClassLoader> copyOfClassLoaders = new HashSet<>(classLoaders);
for (ClassLoader classLoader : copyOfClassLoaders) {
removeClassLoader(classLoader);
}
if (beanFactory != null) {
beanFactory.destroy();
}
if (extensionDirector != null) {
extensionDirector.destroy();
synchronized (instLock) {
if (destroyed.compareAndSet(false, true)) {
try {
onDestroy();
HashSet<ClassLoader> copyOfClassLoaders = new HashSet<>(classLoaders);
for (ClassLoader classLoader : copyOfClassLoaders) {
removeClassLoader(classLoader);
}
if (beanFactory != null) {
beanFactory.destroy();
}
if (extensionDirector != null) {
extensionDirector.destroy();
}
} catch (Throwable t) {
LOGGER.error(CONFIG_UNABLE_DESTROY_MODEL, "", "", "Error happened when destroying ScopeModel.", t);
}
} catch (Throwable t) {
LOGGER.error(CONFIG_UNABLE_DESTROY_MODEL, "", "", "Error happened when destroying ScopeModel.", t);
}
}
}
Expand Down

0 comments on commit ba14a20

Please sign in to comment.