• 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

Running multiple applications using a single VM

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone
Does anyone know whether i can run say, 10 different (in logic scope) java apps without launching 10 instances of the VM?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]


 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it thanks BTW, when you are talking about a classloader are you refering to the use of the reflection library?
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic