• 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 programs in single JVM

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I'm interested on running multiple program within a single JVM. for a instance, let say, I want to run two instances of same hello world program in a one JVM. I would like to know it is possible and if it possible I'm expecting a resource to learn how to do it by myself.

Thanks & Regards,

Nuwan Aramabage
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm interested on running multiple program within a single JVM


Would you give more information what you want to do? whether you want to create multiple threads in single JVM or run multiple programs in single JVM?
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm interested in running multiple programs in a single JVM.

 
Ninad Kulkarni
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm interested in running multiple programs in a single JVM.


Ok

I want to run two instances of same hello world program in a one JVM.


Also want to know about it.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The public static void main(String[]) method is in the end still a method. You can call it like any other static method, provided you give the required arguments. Running it in a separate thread is probably a good idea.

There is one thing to be careful about. If the program calls System.exit that will not only exit that program but also all other programs running from your launcher. This also includes user interface frames with Frame.EXIT_ON_CLOSE set as the default close operations.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . why?

You can try opening them with Runtime.getRuntime().exec(), but make sure to read Michael Dacosta's classic article before you go anywhere near Runtime#exec().
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be aware that multiple applications running within a single JVM would share static variables, singletons etc. That's why application servers separate applications through the use of classloaders, and why they normally associate security managers with each application (or application classloader), so that applications can't interfere with one another. Calls to System.exit() which Rob mentioned are just one example of this.
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't get what you guys are talking about.. I do have a clear question... Is there a mechanism to run two instances of the same program within a single JVM. If it is possible, how can we do it..

I'm looking for a solid answer.. this question intrigues me a lot..

Thanks

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nuwan Arambage wrote:Is there a mechanism to run two instances of the same program within a single JVM. If it is possible, how can we do it..


Rob answered that - you can call the main method. But as both Rob and I mentioned, there may be problems if the applications aren't aware that other application instances may be running in the same JVM.
 
Ninad Kulkarni
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nuwan wrote:I didn't get what you guys are talking about.. I do have a clear question... Is there a mechanism to run two instances of the same program within a single JVM. If it is possible, how can we do it..

I'm looking for a solid answer.. this question intrigues me a lot..



@Nuwan
Why that question intrigues you a lot?
Read the posts from Ulf & Rob again they already given answer to your question.
 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes people, I'm sorry I was in hurry...
I got the point you guys explained..
 
Ninad Kulkarni
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NoNeedToSaySorry
 
This is awkward. I've grown a second evil head. I'm going to need a machete and a tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic