This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have finished reading HFSJ second time and currently am preparing for the exam with the help of Enthuware JWeb Plus V5.
The question(QID com.enthuware.ets.scwcd.v5.2.328) is "Assuming that a web application is marked as distributed, which of the following statements are correct:" and one of the correct answers was "All request that belong to a session are handled by one JVM at a time."
Could somebody please explain this to me? I thought that session migration happens exactly when different requests come for one session to different JVMs.
How I understand it:
Say a user has made request1, which was sent to JVM1 and which created a session. Then the users make request 2 and it is sent to another JVM, say, JVM2. The container sees that the session associated with this request is on JVM1 and migrates the session object to JVM2. That is when SessionActivationListener gets informed.
Am I wrong?
If "All request that belong to a session are handled by one JVM at a time." then in what case does the migration happen?
By reading your story I think that you understood it well.
But what the authors (enthuware) might have wanted to say is that there are not two requests handled by two JVMs at the same time. The Session object is not replicated but migrated. If the Session object was available in both JVMs at the same time it could handle each incoming request without having to migrate.