• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple instances

 
S Sravs
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HFSJ 1.4
pg no.183 Dumb Question
Dog is a Customer class,with each active instance representing a single suctomer's info for name,address,orfer info,etc

pg no.202 last Dumb Question
Stop rught there! you say "multiple instances fo the servlet".We know there is always only ONE instance of the servlet.One instance,many threads.

If servlet dont have multiple instances then how does Dog class can have multiple instances

thanks inadvance
Sravanthi
 
winay Kumar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Servlets wil have only one instance and multiple threads for each request. But this Dog class in not a servlet class. its like having multiple session objects for each active clients.
 
S Sravs
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if that is the case then listener class too have multiple instances
container at first request set the listener class then for every request listener "instances" are created
is that correct
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure, To end your curiosity write some short programs.

best regards,
omi
 
winay Kumar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

for the objects which you want to monitor when its added to session or when its removed from session for those classes only we will implement HttpSessionBindingListener inteface.

for example if you want to add Name, Address to session usually we will create String Variables right? In that case we cannot use HttpSessionBindingListener inteface. in that case we will create a class which implements HttpSessionBindingListener inteface. In that class we will declare String variable like String name, setter and getter methods for that variable and we will define interface methods valueUnbound, valueBound.

the author is telling like if we want to monitor name, address and info etc.. we will have to create a class for each thing. obviously we will have
multiple instance for each class for each session.
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I would say this is not true.

The container will create an instance of the listener class to receive events and this instance could handle multiple threads just like servlets.
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can we know, whether there are multiple objects or threads created for a Servlet ? only through books ?
or do we have any API methods or class to code ?

to now number of threads we can create a instance variable and increment it in class constructor, how about threads ? how to know the number of threads created for servlet ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic