Bug 50157

Summary: a lot of MapperListener is registered as ContainerListener of StandardContext
Product: Tomcat 7 Reporter: Eiji Takahashi <mashmk02>
Component: ConnectorsAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: minor    
Priority: P2    
Version: trunk   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: patch for MapperListener.java

Description Eiji Takahashi 2010-10-26 03:28:12 UTC
Created attachment 26213 [details]
patch for MapperListener.java

The same five MapperListener is registered as ContainerListener of StandardContext. 

At first when I add StandardHost by using "Engine addChild operation" via JMX, same MapperListener is registered as ContainerListener of StandardHost.

StandardEngine.addChild()
->StandardEngine.addChildInternal()
  ->StandardEngine.fireContainerEvent()
    ->MapperListener.containerEvent() line: 133 <-- here
      ...
    ->MapperListener.containerEvent() line: 135
      ->MapperListener.registerHost() line: 276 <-- here

Therefore, StandardHost has the same two MapperListener as ContainerListener. 
---

Then, starting StandardHost by using "Host start operation", the same five MapperListener is registered as ContainerListener of StandardContext. 

(1)LifecycleState of StandardHost is changed to STARTING.
StandardHost(LifecycleBase).start() line:140
->StandardHost(ContainerBase).startInternal()
  ...
  ->StandardHost(ContainerBase).fireContainerEvent <-- fireContainerEvent fire two times
    ...
    ->MapperListener.containerEvent() line:133 <-- here
    ...
    ->MapperListener.containerEvent() line:137
      ->MapperListener.registerContext() line:339 <-- here

(2)LifecycleState of StandardHost is changed to STARTED.
StandardHost(LifecycleBase).start() line:156
...
->MapperListener.registerHost() line:279
  ->MapperListener.registerContext() line:339 <-- here
---
I think that the memory is wasted a little because of the above issue.

On a related issue, MapperListener is not registered as Container/LifecycleListener for StandardContext on starting up Tomcat.


I attached the patch for above issues.

Best regards.
Comment 1 Mark Thomas 2010-10-26 18:12:30 UTC
Thanks for the report and the suggested patch.

After some review, I went with a different patch that simplifies when objects get registered and some additional debug logging. I don't think there are any code paths where the listener can get registered twice but if you spot any feel free to re-open this issue.

I also added some debug logging and exposed the listener names via JMX for easier debugging.