SmartSolution
SmartSolution

Reputation: 2348

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 between 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.

Upvotes: 3

Views: 2112

Answers (5)

Andrey
Andrey

Reputation: 6796

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:

Upvotes: 0

Genzer
Genzer

Reputation: 2991

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

Upvotes: 2

Csujo
Csujo

Reputation: 507

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

Upvotes: 4

Ham Vocke
Ham Vocke

Reputation: 2994

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.

Upvotes: 1

seand
seand

Reputation: 5296

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.

Upvotes: 0

Related Questions