This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes one servlet container per server or per JVM? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "one servlet container per server or per JVM?" Watch "one servlet container per server or per JVM?" New topic
Author

one servlet container per server or per JVM?

Caly LeeAnn
Ranch Hand

Joined: Nov 22, 2005
Posts: 55
Is one servlet container per server or per JVM?

I think it's one servlet container per server. What do you think?
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

What should stop me from hosting two containers working on different ports with two different instances of the JVM (one for each container) on one server ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Sunil Kumar Jakkaraju
Greenhorn

Joined: Oct 06, 2006
Posts: 24

What should stop me from hosting two containers working on different ports with two different instances of the JVM (one for each container) on one server ?


John, how can we accomplish that? Is it by enabling clustering in the web server. So if I want to call a servlet MyServlet on that server, how does the server choose what container on what JVM will respond?


Thanks & regards,
Sunil
When all else fails, follow instructions. - Allen's Axiom
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Nothing is stopping you from running multiple servlet containers side by side on the same server (hardware).
Each has its own webserver built in to serve the generated content.

Whether you can plug multiple servlet containers into a single Apache (for example) instance is another question, and one to which I don't know the answer.


42
Dan Howard
Ranch Hand

Joined: Feb 22, 2004
Posts: 47
John, how can we accomplish that? Is it by enabling clustering in the web server. So if I want to call a servlet MyServlet on that server, how does the server choose what container on what JVM will respond?


I'm not John, but I'll try to answer anyway.

For Tomcat, you can simply install a second instance and then modify server.xml and change the port number. Look for the Connector port setting. Server.xml would be in the conf folder under where you installed Tomcat.

At the servlet level servlets don't choose where to respond. They're simply doing a request/response on that single connection. In other words, at the application level there's no need to think about this.

For a servlet container what clustering does is replicate the users session object on each web server. Say you had 4 web servers and you set up clustering using Tomcat's built-in clustering. What happens is that in your code whenever you set an attribute on the session object it gets serialized and sent to each web server. So each web server has a copy of that session object. In the event a web server goes down the load balancer (another piece of this puzzle) will redirect the request to another web server. Since that second web server has a copy of the session object the user won't notice any problem. The request will hit the new server and the session will be there already.

Load balancing is the other part of this. Usually you can have a software load balancer (Apache can be used for this) or a hardware load balancer.
All the load balance basically does is see if a particar web server can repond to the request. If the web server it's trying to talk to is not responding then it redirects to another web server.

Hope this helps.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

For a servlet container what clustering does is replicate the users session object on each web server.


I found a tomcat article about this. Have a look if you have time. I dont know how to configure these clusters. It would be interesting to learn though.

http://tomcat.apache.org/tomcat-5.5-doc/cluster-howto.html
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

A Servlet will run with one instance on each JVM.

In a clustered environment, many JVMs work on either the same machine (vertical scaling) or on separate machines(horizontal scaling) to provide load balancing and failover support. A client request may be sent to any JVM participating in this workload management scheme, although the idea of 'sticky sessions' still remains.

Since a client can potentially have their request handled by any JVM, the Servlet being invoked must be running on each JVM participating in the cluster.

-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: one servlet container per server or per JVM?
 
Similar Threads
Static & Instance in Servlet
Servlets and JVM!
ActionServlet instances
Multiple threads of a servlet instance and servletConfig
when init() method is called ?