• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JVM and Classloader

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Edwin,

Thanks for the detailed explanation. That gave me more insight on this and thanx for the link.
 
reply
    Bookmark Topic Watch Topic
  • New Topic