title: Does the servlet specification guarantee single thread initialization and inline attributeChanged events?
body: <p>I have a web application that bootstraps event-receiver from external system when a ServletContext is initialized. All components that need to receive events are listening for ServletContext attribute events and attaching themselves as listeners. As I do not want the event-listeners to miss events, I want to start the event-source only after all listeners have been attached. </p>
  
  <p>I could not find any threading requirements for initialization in the Servlet 2.5 and 3.0 specification, so I was assuming completely async initialization model, yet I noticed that Tomcat fires the ServletContext attribute-changed events immediately from the setAttribute() method. This would mean that if all other servlet containers follow suit, I can simplify my startup procedure. </p>
  
  <p><strong>EDIT:</strong> As requested, here is an example (I have tried to be as concrete as possible). In my web.xml, I  currently have registered:</p>
  
  <ul>
  <li><strong>BootstrapEventSourceContextListener</strong> on servlet-context initialization:
  <ol>
  <li>creates event-source and sets it as servlet-context attribute. </li>
  <li>the event-source is not started at this time (i.e. it does not emit events)</li>
  </ol></li>
  <li><strong>ConsumerAContextAttributeListener</strong> when it receives a notification that the attribute containing the event-source has been set:
  <ol>
  <li>looks up the event-source from the servlet-context attribute</li>
  <li>instantiates ConsumerA </li>
  <li>attaches ConsumerA to the event-source</li>
  <li>sets the data model of ConsumerA as attribute in the servlet-context</li>
  </ol></li>
  <li><strong>ConsumerBContextAttributeListener</strong> - same as Comsumer A</li>
  <li><strong>ConsumerCContextAttributeListener</strong> - same as A and B, except that it also depends on the datamodel of B</li>
  <li><strong>StartEventSourceFilter</strong> when a page is accessed:
  <ol>
  <li>looks up the event-source from the servlet-context</li>
  <li>starts the event-source </li>
  <li>blocks until the event-source has received initial snapshot</li>
  <li>continues to render the page</li>
  </ol></li>
  </ul>
  
  <p>The question is whether I really need the StartEventSourceFilter, or is it guaranteed that all the consumers will be attached the moment I set the event-source attribute (i.e. attribute listeners are not deferred). I care about Tomcat, Jetty and Websphere.</p>