• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Session persistance over 2 JVMs

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,

Does the session persist over 2 JVMs.
ie if I want to call action class of an application on JVM2 from JSP on JVM1, does the form beans and/or session data will be available in that action class?
Need a quick help, please !!!

Thanks in Advance,
Lalit Bhabal
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Marcus Green Tutorial :- The JSP/Servlet standard does not require that a web container supports distributed applications, but it must support the HttpSessionActivationListener interface, to allow code to be capable of supporting such an environment. The HttpSessionActivationListener has two methods.

public void sessionDidActivate(HttpSessionEvent se)
public void sessionWillPassivate(HttpSessionEvent se)

The specification mandates that a container may migrate a session to another JVM for purposes such as load balancing or fail-over. This type of capability is considered vital for the deployment of large scale web application

Session passivation is where inactive sessions are written to a persistent store. Session activation is the ability to a previously passivated session into memory from the persistent store. For an attributes to be migrated between distributed JVM's any attributes must implement the java.io.Serializable interface. This is not a very taxing programming task as Serializable is a marker interface i.e. it has no methods. .

With the exam perspective , the above things are enough to know.


If you hav the ask Q to implement then you shd knw few more things.

Load balancing with multiple machines either uses sticky sessions or symmetrical sessions.Sticky sessions put more intelligence on the load balancer, and symmetrical sessions puts more intelligence on the JVMs. The choice of which to use depends on what kind of hardware you have, how many machines you're using and how you use sessions.


Symmetrical Sessions
Symmetrical sessions happen with dumb load balancers like DNS round-robin. A single session may bounce from machine A to machine B and back to machine B. For JDBC sessions, the symmetrical session case needs the always-load-session attribute described below. Each request must load the most up-to-date version of the session.

Distributed sessions in a symmetrical environment are required to make sessions work at all. Otherwise the state will end up spread across the JVMs. However, because each request must update its session information, it is less efficient than sticky sessions.

Sticky Sessions
Sticky sessions require more intelligence on the load-balancer, but are easier for the JVM. Once a session starts, the load-balancer will always send it to the same JVM. Resin's load balancing, for example, encodes the session id as 'aaaXXX' and 'baaXXX'. The 'aaa' session will always go to JVM-a and 'baa' will always go to JVM-b.

Distributed sessions with a sticky session environment add reliability. If JVM-a goes down, JVM-b can pick up the session without the user noticing any change. In addition, distributed sticky sessions are more efficient. The distributor only needs to update sessions when they change. So if you update the session once when the user logs in, the distributed sessions can be very efficient.


In Simple words : -
1) When you say session across different JVM - It means same session of same web application in different JVM. There is a common misunderstanding on this.

Mean suppose I have an application like javaranch which is deployed in two machines[2 JVM]Server A and Server B for loadbalancing.Then if suppose 1st request for a servlet was fullfilled by ServerA , the next request frm same user can go to Server B .In this case session can persist across the JVM's if attributes are serialized.

2)In Symmetrical Sessions, When a request come,the loadbalancer is never bothered abt whether where any req has been fullfilled by this user,it just fwd he req to free Server [A or B]. The JVM and container will get the sessionid from cookie ,req url and will get the data from session.both JVM's nw have the session object/attribute .In Symmetrical Sessions, we need to get the session everytime as it may have got updated .

3)In Sticky sessions, logic is in loadbalacer. In the scen, Server A will be confg to generate sessionid strtg with som unique se eg:'aaaXXX' and 'baaXXX'. So when a req come loadbalancer will check the sessionid ,if it is empty it will route the req to any of the server.
if it strts with aaa, then that means a prev req has com and was fulfilled y ServerA, so loadbalancer will forward the req to same JVM.

Some chnage in DD is also reqd.I am not sure on that.

Sorry for the big reply.

Thanks,
Chithra Salam.
SCJP-85%,SCWCD-in Progress.
 
Chithra Salam
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lalit,

if I want to call action class of an application on JVM2 from JSP on JVM1,

.

If in case you need to pass session from one application to another application, then I think you need to pass the session as parameter.

Session persistance across JVMs stands for same application. Most of the people get wrong understanding on this.

Thanks,
Chithra Salam
SCJP-85%,SCWCD-In progress
 
Lalit Bhabal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chithra,

Thanks a ton !!!
It covered everything.

Regards,
Lalit
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chithra Salam wrote:
Sorry for the big reply.



Thanks a lot for sharing this much of good knowledge. I dont think your reply is much more bigger.
 
Chithra Salam
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Right! We're on it! Let's get to work tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic