I have been doing some research in to java servlets and I am having trouble understanding why it more efficient then a cgi based solution.The reason for my lack of understanding is that java servlets run on the thread per request model, meaning that a new thread is spawned or taken from a pool of threads each time a request is made. While a cgi based solution would create a new process per request.My question is, why would creating a process per request be less efficient then a thread, after all in each process is a a thread doing the work, So why is cgi less effecient?
Why is a servlet more efficient than CGI?
java;cgi
java servlets perform way better than cgi due to several reasons.  A few that come to mind:cgi programs typically have much more initialization to do while starting up than a servlet has to do in order to handle a request.  In an unoptimized scenario an entire Java VM has to be started, it has to load classes, transform the bytecode to machine code, etc.Starting a process is far more expensive than starting a thread in any operating system that I have ever heard of.Even if starting a process was as cheap as starting a thread, still, fetching an existing thread from a thread pool is much, much, much more efficient than starting a brand new thread.When a cgi program terminates, all of its state is lost, so when the next request comes in, this state must be reconstructed, (even if it is just configuration,) which usually means loaded from disk.  Servlets can retain important state in memory which is reused across requests.