aspose file tools*
The moose likes Beginning Java and the fly likes JVM and Classloader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JVM and Classloader" Watch "JVM and Classloader" New topic
Author

JVM and Classloader

Nathan Mathi
Greenhorn

Joined: Dec 13, 2005
Posts: 12
Hi,

I've few questions reg JVM and Classloaders.

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?

Thanks,
Nathan.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

"Nathan",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961

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.

For instance:

> java -client com.mydomain.myApp

or

> 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.

I indeed recommend you to read the Java Virtual Machine Specification in section 2.17. That will help you to understand all this process better.

Good luck!
[ June 02, 2006: Message edited by: Edwin Dalorzo ]
Nathan Mathi
Greenhorn

Joined: Dec 13, 2005
Posts: 12
Originally posted by Bear Bibeault:
"Nathan",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

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


I was not aware of this. I modified now.
Nathan Mathi
Greenhorn

Joined: Dec 13, 2005
Posts: 12
Edwin,

Thanks for the detailed explanation. That gave me more insight on this and thanx for the link.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JVM and Classloader