My doubt is How Container figures out about listener type while we never give its type? Can we imagine that Container instantiates all the listeners at deployment time in order to figure out its type? Thanx
<i>--Agrah Upadhyay--</i><br />Final Year B.Tech SCJP,SCWCD,SCBCD <br /> <br /><b>Now since the real test for any choice is having to make the same choice again,knowing full well what it might cost.</b>-Oracle
lalit upadheyay
Ranch Hand
Joined: Jun 20, 2005
Posts: 110
posted
0
through the listener interface type implemented by the class.
SCJP1.4, SCWCD1.4, SCBCD5.0(working on...)
agrah upadhyay
Ranch Hand
Joined: Sep 01, 2005
Posts: 579
posted
0
Thanx.... It means Container instantiates all the listeners at startup time?
TheWeb container creates an instance of each listener class and registers it for event notifications prior to the processing of the first request by the application. The Web container registers the listener instances according to the interfaces they implement and the order in which they appear in the deployment descriptor. During Web application execution, listeners are invoked in the order of their registration.
I guess, that the container instantiates the listenres as needed i.e.
context listeners are instantiated when ServletContext (one for the web app) is created.
request listeners are instantiated when first request arrives. session listeners are instantiated when first session is created.
attribute listeners are instantiated when the attribute class implementing them are instantiated.
agrah upadhyay
Ranch Hand
Joined: Sep 01, 2005
Posts: 579
posted
0
Thanx kurinosuke.....This very was my assumption too. One more thing: while executing sessionCreted() method of HttpSeesionListener class ,if any attribute is added to the session,it should call attributeAdded() method in HttpSessionAttributeListener.But if method sessionCreated() is not completed yet,will Container first transfer the control to attributeAdded() and will come to sessionCreated() later?
agrah upadhyay
Ranch Hand
Joined: Sep 01, 2005
Posts: 579
posted
0
Hai Lalit, just saw your posts but they seem to be wrong.Because Container first wants to instantiate instance of class implementing ServletContextListener. But how will it know about its type until it instantiates it.........Correct me if I am wrong! Thanx
lalit upadheyay
Ranch Hand
Joined: Jun 20, 2005
Posts: 110
posted
0
yes, you are right. listener type cannot be determined before instantaiting the class.
agrah upadhyay
Ranch Hand
Joined: Sep 01, 2005
Posts: 579
posted
0
Lalit also help me regarding one more doubt in this very post.........
One more thing: while executing sessionCreted() method of HttpSeesionListener class ,if any attribute is added to the session,it should call attributeAdded() method in HttpSessionAttributeListener.But if method sessionCreated() is not completed yet,will Container first transfer the control to attributeAdded() and will come to sessionCreated() later?
There is no way that the control will be changed from sessionCreated to attributeAdded. There either two possibilities I think : 1. The container creates a new thread for each listener, so the HttpSessionListener and HttpSessionAttributeListener can both be called at the same time 2. The container does not create new threads, and in this case, you'll have to wait until sessionCreated ends.
Sry, I don't know which one it is. You should not have heavy process in your listeners anyway, so sessionCreated SHOULD be finished before attributeAdded is called