From e42405241789368bc4a120e8b1c9d82d96d94be2 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Mon, 12 Jan 2026 16:57:54 +0100 Subject: [PATCH] WELD-2827 Fire Startup/Shutdown event within a synchronized block --- .../web/servlet/HttpContextLifecycle.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/web/src/main/java/org/jboss/weld/module/web/servlet/HttpContextLifecycle.java b/modules/web/src/main/java/org/jboss/weld/module/web/servlet/HttpContextLifecycle.java index a1e7e427e94..a898cd69153 100644 --- a/modules/web/src/main/java/org/jboss/weld/module/web/servlet/HttpContextLifecycle.java +++ b/modules/web/src/main/java/org/jboss/weld/module/web/servlet/HttpContextLifecycle.java @@ -149,10 +149,10 @@ public HttpRequestContext getRequestContext() { public void contextInitialized(ServletContext ctx) { servletContextService.contextInitialized(ctx); - fireEventForApplicationScope(ctx, Initialized.Literal.APPLICATION); + fireSynchronizedEvent(ctx, ServletContext.class, Initialized.Literal.APPLICATION); Environment env = Container.getEnvironment(); if (module != null && env != null && env.automaticallyHandleStartupShutdownEvents()) { - module.fireEvent(Startup.class, new Startup(), Any.Literal.INSTANCE); + fireSynchronizedEvent(new Startup(), Startup.class, Any.Literal.INSTANCE); } } @@ -160,25 +160,25 @@ public void contextDestroyed(ServletContext ctx) { // firstly, fire Shutdown event Environment env = Container.getEnvironment(); if (module != null && env != null && env.automaticallyHandleStartupShutdownEvents()) { - module.fireEvent(Shutdown.class, new Shutdown(), Any.Literal.INSTANCE); + fireSynchronizedEvent(new Shutdown(), Shutdown.class, Any.Literal.INSTANCE); } // TODO WELD-2282 Firing these two right after each other does not really make sense - fireEventForApplicationScope(ctx, BeforeDestroyed.Literal.APPLICATION); - fireEventForApplicationScope(ctx, Destroyed.Literal.APPLICATION); + fireSynchronizedEvent(ctx, ServletContext.class, BeforeDestroyed.Literal.APPLICATION); + fireSynchronizedEvent(ctx, ServletContext.class, Destroyed.Literal.APPLICATION); } - private void fireEventForApplicationScope(ServletContext ctx, Annotation qualifier) { + private void fireSynchronizedEvent(Object payload, Class payloadClass, Annotation qualifier) { if (module != null) { // Deliver events sequentially synchronized (container) { if (module.isWebModule()) { - module.fireEvent(ServletContext.class, ctx, qualifier); + module.fireEvent(payloadClass, payload, qualifier); } else { // fallback for backward compatibility ServletLogger.LOG.noEeModuleDescriptor(beanManager); - final EventMetadata metadata = new EventMetadataImpl(ServletContext.class, null, + final EventMetadata metadata = new EventMetadataImpl(payloadClass, null, Collections.singleton(qualifier)); - beanManager.getAccessibleLenientObserverNotifier().fireEvent(ServletContext.class, ctx, metadata, + beanManager.getAccessibleLenientObserverNotifier().fireEvent(payloadClass, payload, metadata, qualifier); } }