Re: Process vs Thread: what are the consequences?
"Daniel Pitts" wrote:
If memory serves, JVMs on Linux will actually create an OS level
sub-process for every Thread spawned.
That depends on which JVM you use. The current crop of Sun JVMs use native
threads on Linux and Solaris. I don't know what they do on Windows or Macs.
<http://java.sun.com/j2se/1.4.2/reference/whitepapers/index.html#12>
In any case, I think that there would be at least as much overhead, if
not more, to creating two JVM instances than one JVM instance with two
threads.
Your final solution is more likely to depend on the amount of
inter-process/thread communication you're engine is going to need.
Java supports threads natively. Multiple-process coordination is harder.
Programming for multiple processes that don't communicate is probably easier.
A properly-designed multi-threaded Java program is going to have better
control and coordination than a multi-process solution, and will have less
overhead.
A badly-designed multi-threaded Java program will give heartaches.
A single JVM is able to optimize a lot of things among threads that multiple
processes will not be able to. For example, a number of scenarios that
involve synchronization can actually optimize away the synchronization.
--
Lew