1. Are multiple JVMs be installed in single machine/processor? 2. If so, there is a chance to have each classloader in each JVM per machine/processor, right? 3. What is the ideal production environment, does it have multiple JVMs in single processor? If so, how to avoid Classcastexception if we have same class instance in both the JVMs?
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks! bear JavaRanch Sheriff
Post by:Edwin Dalorzo
, Ranch Hand
1. Are multiple JVMs be installed in single machine/processor?
The JVM behaves just like another OS process. Hence, you can run as many JVM as resources are available on your machine. Every JVM is independently treated as process by the underlying operating system. How the OS assigns processor resources to each JVM has nothing to do with the JVM itself, but with the OS.
2. If so, there is a chance to have each classloader in each JVM per machine/processor, right?
Actually every JVM creates its own ClassLoader known as the Bootstrap ClassLoader. This one loads the core Java classes. Apart from this, an application can have multiple user ClassLoaders. Two different ClassLoaders can load the same class without interfering with each other. However, you must understand that ClassLoaders in independent instances of the JVM are running in completely different processes, and are completely unaware of their mutual existence.
3. What is the ideal production environment, does it have multiple JVMs in single processor? If so, how to avoid Classcastexception if we have same class instance in both the JVMs?
First of all, ClassCastException has nothing to do with the ClassLoader, as far as I am concerned. It has to do with polymorphism, and it typically happens due to a programming error, that's why it is a RuntimeException.
Now, regarding JVM. Typically you create an instance of the JVM for every Java application your computer is running. They do not talk to each other, unless you explicitly program an inter process communication using Sockets or RMI.
Sun has created two implementations of the JVM Virtual Machine known as the Java Hot Spot Virtual Machine. They have a client and server version. An instance of one them is created every time you launch an application by means of the java application launcher.
> java -client com.mydomain.myApp
> java -server com.mydomain.myApp
Will automatically start an instance of the Java Hostspot Virtual Machine.
I have the impression that you are a bit confused about the JVM execution and about what class loading implies.