I have a Tomcat 7 webapp, in which I have two different ServletContextListener
.
Example:
Listener A
public class ListenerA implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce){
ObjectA objectA = new ObjectA();
context.setAttribute("objectA", objectA);
}
...
}
Listener B
public class ListenerB implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce){
ObjectB objectB = new ObjectB();
context.setAttribute("objectB", objectB);
}
...
}
web.xml
...
<listener>
<description>ListenerA</description>
<listener-class>com.example.web</listener-class>
</listener>
<listener>
<description>ListenerB</description>
<listener-class>com.example.web</listener-class>
</listener>
...
¿Does the order of appearance in web.xml
affect to load process, or are they loaded in different threads?
I'd like to know if it's possible to get ObjectA from context in ListenerB. I can always merge both listeners into a unique one so I'd be able to have both objects A and B in the same listener, but I want to know if this is possible.
I know I have the option to use attributeAdded
from ServletContextAttributeEvent
interface, but, will this be enough to do the work or can it fail if the ListenerB loads before the ListenerA?
Ok, so I've finally found the answer here
So the load order is determined strictly by the order of appearance in web.xml