@@ -213,7 +213,10 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
213
213
private boolean webApplicationContextInjected = false ;
214
214
215
215
/** Flag used to detect whether onRefresh has already been called */
216
- private boolean refreshEventReceived = false ;
216
+ private volatile boolean refreshEventReceived = false ;
217
+
218
+ /** Monitor for synchronized onRefresh execution */
219
+ private final Object onRefreshMonitor = new Object ();
217
220
218
221
219
222
/**
@@ -490,8 +493,8 @@ public void setApplicationContext(ApplicationContext applicationContext) {
490
493
@ Override
491
494
protected final void initServletBean () throws ServletException {
492
495
getServletContext ().log ("Initializing Spring FrameworkServlet '" + getServletName () + "'" );
493
- if (this . logger .isInfoEnabled ()) {
494
- this . logger .info ("FrameworkServlet '" + getServletName () + "': initialization started" );
496
+ if (logger .isInfoEnabled ()) {
497
+ logger .info ("FrameworkServlet '" + getServletName () + "': initialization started" );
495
498
}
496
499
long startTime = System .currentTimeMillis ();
497
500
@@ -500,13 +503,13 @@ protected final void initServletBean() throws ServletException {
500
503
initFrameworkServlet ();
501
504
}
502
505
catch (ServletException | RuntimeException ex ) {
503
- this . logger .error ("Context initialization failed" , ex );
506
+ logger .error ("Context initialization failed" , ex );
504
507
throw ex ;
505
508
}
506
509
507
- if (this . logger .isInfoEnabled ()) {
510
+ if (logger .isInfoEnabled ()) {
508
511
long elapsedTime = System .currentTimeMillis () - startTime ;
509
- this . logger .info ("FrameworkServlet '" + getServletName () + "': initialization completed in " +
512
+ logger .info ("FrameworkServlet '" + getServletName () + "': initialization completed in " +
510
513
elapsedTime + " ms" );
511
514
}
512
515
}
@@ -558,7 +561,9 @@ protected WebApplicationContext initWebApplicationContext() {
558
561
// Either the context is not a ConfigurableApplicationContext with refresh
559
562
// support or the context injected at construction time had already been
560
563
// refreshed -> trigger initial onRefresh manually here.
561
- onRefresh (wac );
564
+ synchronized (this .onRefreshMonitor ) {
565
+ onRefresh (wac );
566
+ }
562
567
}
563
568
564
569
if (this .publishContext ) {
@@ -808,7 +813,9 @@ public void refresh() {
808
813
*/
809
814
public void onApplicationEvent (ContextRefreshedEvent event ) {
810
815
this .refreshEventReceived = true ;
811
- onRefresh (event .getApplicationContext ());
816
+ synchronized (this .onRefreshMonitor ) {
817
+ onRefresh (event .getApplicationContext ());
818
+ }
812
819
}
813
820
814
821
/**
0 commit comments