• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

container and context

 
Jerry Bustamente
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few questions if I may:

1. A colleague told me that there is more than one servlet context object in a given container. I thought that a container was for a single application.

Can there be more than one context object in a single container?

2. My colleague went on to say that there is a special area of memory in a container where the contex object resides. I have not read of such an area. I thought a context object would occupy an area of the container memory where servlets lived and that there was no special area in the container reserved for a context object.

Is there a special area in the container's memory set aside for context objects?

Thanks alot,

Jerry Bustamente
 
Jose Esteban
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. A container can host several web applications. If you have used anytime a servlet container, you should know that. Moreover, does an Internet Service Provider need a new servlet container for every web app it hosts?

2. I have no idea about that. As far as I know, there must be a one to one correspondence between a Web application and a ServletContext. I think that memory management is a responsibility of the JVM, so I don't know why your colleague said that.

Regards,
Jose
 
Rafael Pereira
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, according to Tomcat architecture definitions:

"A Context represents a web application. A Host may contain multiple contexts, each with a unique path."
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a special area in the container's memory set aside for context objects?
I am just guessing here, but I would assume that memory management is container dependent. For instance, Tomcat may do it one way, and websphere may do it totally different...

As far as the multiple contexts per container... that is correct. There is only one context per application, but there may be multiple applications per container.
 
James Christian
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah the context has a 1 to 1 relationship with web-apps (i.e. each web-app has 1 and only 1 context). However, as has rightly been pointed out a container, e.g. tomcat typically runs more than one web-app and so technically there can be more than one context in a container. BUT FOR THE EXAM YOU ONLY NEED TO KNOW THAT FOR EACH WEB-APP THERE IS ONLY ONE CONTEXT WHOSE SCOPE IS ACCESSIBLE TO ALL THE COMPONENTS IN THAT APP. You won't need to anything about containers with multiple apps.

Insofar as memory concerns I really don't know but I should imagine that as an object the context lives on the heap just like all other objects until they are garbage collectec, which in the case of the context object would not happen until tomcat is shutdown. The one thing I do know is this: THERE IS NO MENTION OF MEMORY MANAGEMENT FOR CONTEXT OBJECTS IN THE EXAM OBJECTIVES. So I would't worry about it too much.

Have you got the Head Firt Servlets & JSP book? It's a great book and I think it could put your mind at rest on a number of issues.
 
Jerry Bustamente
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose, Rafael, Paul, and James,

Thank you very much for taking the time to reply as well as for you guidance regarding the exam.

I am working through the HFS book. I am at page 207 and unless I missed it, or misinterpreted it, I do not remember mention of more than one app running in a container at the same time. But like I said I may have missed it for one reason or another.

Thanks again.

Sincerely,

Jerry Bustamente
 
James Christian
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't mention it in the book because it's not relevant for the exam but it does say in the book that you have 1 ServletContext object per web-app per JVM, so the point is insinuated but not elaborated on as it won't help you pass the exam.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic