Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Number of Instances

 
Ranjit Jana
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

How many instances of RequestDispatcher will be there in JVM . Is it that for every RequestDispatcher which is got from Request will create different instance. supposedly same behaviour is true with RequestDispatcher got from Servlet Request.

Second question is can there exist More the one Instance of HttpSessionActivationListener , HttpSessionAttributeListener , HttpSessionListener or they are Singletons.

third question is :Can there be instances of two different class but both of type lets say HttpSessionListner in one single JVM
example MyHttpSessionListner is of type HttpSessionListener and NewHttpSessionListener which is also of type HttpSessionListener. so can both of them deployed at same time and both can have one instance in single JVM or container. If yes whose methods will be called first.
 
Ranjit Jana
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant "supposedly same behaviour is true with RequestDispatcher got from ServletContext" .


Was this a wrong question as there is no reply to this.

Wondering ... Huuuu. May be I have some idea about the answer.

each time getRequestDispatcher is called a new instance is created.
but most of the Listener classes are singleton . there cannot be two class which implement lets say HttpSessionListener.Thus only one instance of that listener type.

Am I thinking in correct lines.

Ranajit Jana
 
Stephen Galbraith
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so regarding only one instance of each listener type if by that you mean only ever one HttpSessionListener etc.
From what I've read (and I'm by no means any expert ) you can define multiple listeners in the DD


now both MyListener1 and MyListener2 can implement the same interface (say HttpSessionListener), hence you can have multiple ones.
There are rules regarding the notification order as well, I think they are informed in the order they are specified in.

That's for listeners declared in the DD.

but there are other types of listeners that just get informed if they are "alive" at the time (Hint: attribute....)

Steve
 
Ranjit Jana
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve for the reply.

I agree with you that we can configure Different Class implementing same Listener type. but how is the event lets say contextInitialized() on ServletContextListner will be treated. Will it call both the ListenerType one after other.

I deployed two Listener of ServletContextListener type and tomcat did not throw any deployment error.

Regards,
Ranajit Jana
 
Deb Sadhukhan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Container will call contextInitialized() of MyListener1 first then contextInitialized() of MyListener2, because MyListener1 appeared before MyListener2 in DD.
 
Deb Sadhukhan
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. If I run



then still get a.jsp included in my page. So looks like it returns different objects.

2. Also ard != crd is true.

3.Plus javaDoc of getRequestDispatcher says
Returns a RequestDispatcher object
.

So I'm almost certain each call to getRequestDispatcher returns a new object for the resources.
[ February 18, 2005: Message edited by: Deb Sadhukhan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic