title: Synchronizing session between two web application
body: <h2>Use case:</h2>
  
  <p>I have two web application running on tomcat which are deployed on two different machines. One of my application is a parent and other is a child. I login to my parent application and hitting a link on one of the pages of parent application i sends a browser request to my child application that open's one of its page in a separate browser window. In this scenario i would want both of my application to share the same timeout value and should behave like one complete application.</p>
  
  <h2>Scenarios to handle:</h2>
  
  <ol>
  <li>If i logout from my parent app, my child app should also get logout</li>
  <li>If i close parent window, parent should get logout along with child</li>
  <li>If i close child window, child should get logout and parent should remain logged in</li>
  <li>If both the window are closed, both parent and child should get logout</li>
  </ol>
  
  <h2>Solution:</h2>
  
  <ol>
  <li>Set parent session time out to some value..say 30mins</li>
  <li>Create a REST service on parent..let's say "parentisAlive()"</li>
  <li>Create a REST service on child..let's say "childisAlive()"</li>
  <li>Create session listeners on parent and child</li>
  <li>Each of the session listeners would invoke its respective REST service</li>
  <li>REST service would talk to each other based on its own application's sessionID</li>
  <li>Parent would presist(memory/DB) child's sessionID and vice versa</li>
  <li>Respective applications session listener would get activated when each of its timeout value reaches a specific value..say   20mins</li>
  <li>Session listeners would invoke respective REST service that will be responsible to synch each others session time out value </li>
  </ol>
  
  <p>Can anyone please suggest if this would be a good solution to implement session synchronization, does anyone see any flaw in this?</p>