• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

listener class

 
agrah upadhyay
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
lalit upadheyay
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
through the listener interface type implemented by the class.
 
agrah upadhyay
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx....
It means Container instantiates all the listeners at startup time?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SRV.10.3.3 Listener Registration

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.
 
lalit upadheyay
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you are right. listener type cannot be determined before instantaiting the class.
 
agrah upadhyay
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lalit also help me regarding one more doubt in this very post.........
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by agrah upadhyay:

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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying it, it seems that the container waits until sessionCreated is finished.
You should not have to worry about that kind of problem.
 
agrah upadhyay
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got your point but.......What do you mean by heavy process-in terms of memory?-How?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic