title: Multiple JVMs vs concurrent tasks
body: <p>I am porting fat Java client code to a server architecture with a lean client. </p>
  
  <p>The server needs to run one instance of the code for each client. The code is multithreaded and runs for long times (weeks) but has only occasional interaction with the client. The number of clients will be in the thousands. Each client needs ~20MB of heap.</p>
  
  <p>I have now two options, </p>
  
  <ol>
  <li>start a separate JVM on the server for each client</li>
  <li>modify my code so that all requests and calculation is done in shared space for each client (like in a web-application)</li>
  </ol>
  
  <p>I can see pros and cons for each. For multiple JVMs:</p>
  
  <p>Pros:</p>
  
  <ul>
  <li>processes are separate, if one hangs just kill it and restart. All others won't care.</li>
  <li>resources can be limited, so that one client cannot eat up all CPU / Memory</li>
  <li>easily distributed on several machines</li>
  </ul>
  
  <p>Cons:</p>
  
  <ul>
  <li>the complete JRE class library is loaded multiple times</li>
  <li>not the Java EE way of doing things</li>
  <li>will every client need to talk over a separate port?</li>
  </ul>
  
  <p>Are there any best practices which you recommend? </p>
  
  <p>Do you know of any good reference book / article on the subject?</p>
  
  <p>Is there a framework which uses only one JVM but runs several copies of code as if it was separate process space (with limited resources etc)?</p>