Can I run more than one JVM? If yes then how can I find a particular class is loaded on which JVM?
You can run as many JVMs as you can fit on your disk and in memory :)
Whenever you start a Java application, you're first starting the JVM and then telling it which application to run. The answer to "which JVM" is simply: The JVM that you loaded the application with!
It's possible to do some esoteric fiddling with classloaders which would prove an exception to what I've just said. But it's true in the general case and the majority of all applications.
Multiple JRE (Java Runtime Enviroment) is very possible. I do so. The thing is JVM does not always run on your system. It is like any other software. When you run a jar file, it starts running.
The default JRE is set in Environment Variables as JAVA_HOME (right click my computer -> properties -> advanced tab -> Environment Variables)
To run a jar file you simply run this command:
C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe" -jar Myfile.jar
You can use any other jre javaw to run a jar file.
Please note that j2re1.4.2_04 may not be your jre version.
Edit:
All classes in a jar file run on a single JVM. As you may guess. See your JAVA_HOME, it is the default.
You can run as many as you wish JVM on the same machine. You just need to open several CommandPrompt windows and run what you want via java
or javaw
application. The class that each of the JVM is running is THAT class which contain the main()
method. Main() method is the first thing that runs when you start some Java app. Of course, main() is situated in some of your classes. That's all.
Can I run more than one JVM?
Yes - just run the 'java' process
If yes then how can I find a particular class is loaded on which JVM?
The 'jps' program that is distributed with the JAVA SDK will list all java processes (JVM's) ruinning on your machine, the main class that is being executed by each JVM and the classpath. You'll have to see which jars or classes are on each classpath to figure out if a class is loaded or not.
try running
jps -mlvV
and see what you get
Yes,you can install more than one jvm in your PC, because OS loads an instance of jvm (not whole jvm) in RAM. We can call different jvm like JDK 1.4 or JDK 1.6 by setting its path.
It's not entirely clear what you mean, but:
java
process, whether of the same JVM version or different onesUnless you're running a debugging agent or something similar, I don't know of any way to ask a JVM process whether it's loaded a particular class. It seems a bit of an odd requirement - why do you want to do this?