Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8682737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:51:18+00:00 2026-06-12T21:51:18+00:00

I have a Tomcat 7 webapp, in which I have two different ServletContextListener .

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:51:19+00:00Added an answer on June 12, 2026 at 9:51 pm

    Ok, so I’ve finally found the answer here

    All servlet containers an J2EE containers implement this part of the spec strictly. You can rely on the fact that the listeners are called in the order you specified in web.xml.

    You can have a Application LEVEL Data structure(HashMap) that will be updated by each Filter/Listener as it encounters the data from the requests. This will let each Listener update only what is essential. You can put the common code in a base Listener so that there is no code duplication.

    So the load order is determined strictly by the order of appearance in web.xml

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Struts2 webapp, in which I compiled using the Tomcat 5.5 libraries.
I have a GWT webapp, running under Tomcat, with the following remote service: public
I have a Tomcat Java webapp which is thrashing the Java GC when under
I have a Tomcat 5.5 running which includes a Webapp with the Java Reporting
I have two queries which I am detailing below: I installed tomcat 7.0 on
In my webapp which is deployed in tomcat environment, I have one spring configuration
I have a Tomcat webapp which does some pretty memory and CPU-intensive tasks on
I have two web applications living on the same Tomcat installation, in which I
I have a webapp running in Tomcat which uses Spring for dependency injection. (It's
I have a webapp based on Spring 3.0.6 which works fine on Tomcat 7.0.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.