开发者

Can multiple java applications run under same VM?

I am running two different java applications and both are running of different JVMs. Actually I need to pass some data bet开发者_如何学Pythonween these applications, I am already using shared file approach here but looking for more better approach.

So what I am thinking is that if somehow we are able to run these apps under same JVM and then may we can pass data between these apps. I don't know how can we pass data between apps running under same JVM.


The technology of data transfer between 2 application is the RMI in Java, I think you should use that.

Here is an introduction for this: Introduction to Java RMI


You can implement your apps contact to each other through Socket.


Effectively they do when you use an application server. An application server usually runs your application in an own thread instead of on JVM for each application. If you want to achieve a similar solution you could write a primitive server that calls your application's main method in specific threads.

Be aware though that this also might give you some additional headache. If one thread exits the application with System.exit(0) for instance, all of your threads will be shut down.


Provided your apps don't have inherent conflicts (incompatible JVM parameters, conflicting singletons etc) it's likely doable. You'll likely have to modify your main() method some way; perhaps have your 2 apps run in their own threads.

However without knowing additional details it's hard to judge things.


For your task you need not run the apps under same JVM instance.

You can pass data between different JVMs. There are bunch of solutions available.

For example:

  • RMI (I think this one is most appropriate in your case) http://en.wikipedia.org/wiki/Java_remote_method_invocation
  • JGroups http://www.jgroups.org/
  • JMS http://en.wikipedia.org/wiki/Java_Message_Service
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜