• Post Reply Bookmark Topic Watch Topic
  • New Topic

Running multiple programs in single JVM  RSS feed

 
Nuwan Arambage
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I'm interested in running multiple programs in a single JVM.

 
Ninad Kulkarni
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Posts: 21117
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56223
171
  • Mark post as helpful
  • send pies
  • 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().
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42972
73
  • Mark post as helpful
  • send pies
  • 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: 802
Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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: 802
Java Linux
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!