It's not a secret anymore!*
The moose likes Java in General and the fly likes Running multiple applications using a single VM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running multiple applications using a single VM" Watch "Running multiple applications using a single VM" New topic
Author

Running multiple applications using a single VM

Jander
Greenhorn

Joined: Mar 23, 2001
Posts: 2
Hello everyone
Does anyone know whether i can run say, 10 different (in logic scope) java apps without launching 10 instances of the VM?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You can have one driver program that launches the other programs using

Runtime.getRuntime().exec("java myClass");
This thread has an example: http://www.javaranch.com/ubb/Forum33/HTML/000194.html


"JavaRanch, where the deer and the Certified play" - David O'Meara
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Oh yeah, and Jander:

The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at "JavaRanch Naming Policy" . We require names to have at least two words (not just letters), separated by a space, and strongly recommend that you use your full real name. We want to get to know you as a Professional. Please choose a new name which meets the requirements and re-register.
Cindy
Jander
Greenhorn

Joined: Mar 23, 2001
Posts: 2
Yes ma'am

Originally posted by Cindy Glass:
Oh yeah, and Jander:

The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at [b]"JavaRanch Naming Policy"
. We require names to have at least two words (not just letters), separated by a space, and strongly recommend that you use your full real name. We want to get to know you as a Professional. Please choose a new name which meets the requirements and re-register.
Cindy[/B]

Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I don't think Cindy's suggestion actually achieves what you are asking for. Using Runtime.exec() like that will start a new JVM for each command - the same as if you had started them manually.
If your "applications" really are separate, then running them in the same VM is basically a matter of putting their classes and jars in the classpath, and executing the main method of their entry point class in a new thread:

If you are in the unlucky situation of each application needing a separate copy of certain static variables or singletons, then you will have to create your own classloader to load each application.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Got it thanks BTW, when you are talking about a classloader are you refering to the use of the reflection library?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Sort of. A classloader is a Java object which manages the loading of classes. Typically classes are loaded from class files on a filesystem, or from a jar file, or from a URL (think applets), but it is possible to write your own classloader to load classes from anywhere or from any format.
Common custom classloader implementations include reload-if-modified classloaders as used in JSP containers and some test harnessses etc.
Siva Prasad
Ranch Hand

Joined: Feb 22, 2001
Posts: 104
Yep Jander!
you can run any number of java programs in a Single VM using ClassLoader objects.
Today only I've read about this topic, so got very excited to reply this topic.
But keep in mind that, you cannot create an instance of ClassLoader from the Java API. Its an Abstract Class.
The mostly used ClassLoader for these purposes is...URLClassLoader
With which you can load any class from anywhere.
Cheers
Siva
 
wood burning stoves
 
subject: Running multiple applications using a single VM
 
Similar Threads
PA #1.....picture association
badges vs degree