Meaningless Drivel is fun!*
The moose likes Distributed Java and the fly likes JVM to JVM Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "JVM to JVM Communication" Watch "JVM to JVM Communication" New topic
Author

JVM to JVM Communication

NamrataS Sinha
Greenhorn

Joined: Feb 19, 2012
Posts: 6
Hi,

I am very new to Java Ranch. So please pardon me if there is any mistake in asking or selecting topic.
I am trying to find out the most efficient way for communication between two JVM. I know that determining best suitable method is selected as per the requirement.
In my case I want to allow two JVMs of Core Java app(Stand-alone/ non-enterprise app) to communicate.
For standalone apps I found the below methods :
1. Socket programming.
2. RMI
3. Sharing Files (File IO/ Serializing)
Is there any other method available for stand-alone apps in Java?

Please help me for judging the correct method.
Quick response will be appreciated..


Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
  • a shared DB
  • web services (arguably a higher form of socket comm.)
  • Ram Narayan.M
    Ranch Hand

    Joined: Jul 11, 2010
    Posts: 247

    If simply want two JVMs to be communicated, RMI is the best option.

    "Socket Programming" is a raw mode which has to be dealt very carefully.


    SCJP 6 [SCJP - Old is Gold]
    William Brogden
    Author and all-around good cowpoke
    Rancher

    Joined: Mar 22, 2000
    Posts: 12778
        
        5
    Another high level communication approach is JMS Java Message Service - which requires a separate JMS server but has the great advantage of being asynchronous.

    Direct socket programming / RMI and web services require that both JVMs work together.

    Shared DB, shared file, JMS permit one JVM to drop off information which the other can pick up as it is convenient.



    Given that Java was developed by a company whose slogan was "the network is the computer" it is not surprising to find so many communication methods.

    Bill
    Bhanuprakash Sreenivas
    Greenhorn

    Joined: Jan 01, 2010
    Posts: 8

    You need to be more specific about your needs.
    Like if it is a critical application , JMS would be a good choice.

    Other options,

    1. Avoid serialization since it will have compatibility issues .
    One lightweight alternative you can explore is Google Protocol Buffers.

    2 . Using a JMS should be an ideal choice based on how robust you want your applications to be.
    But you need to keep in mind the following.
    - Heavyweight , since it will be yet another process inbetween the two JVM process
    - Need to use transactions to make it perfect.

    3 . Expose as a webservice .
    NamrataS Sinha
    Greenhorn

    Joined: Feb 19, 2012
    Posts: 6
    Tim Moores wrote:
  • a shared DB
  • web services (arguably a higher form of socket comm.)


  • Hi Tim,

    Thanks for the reply.
    Web services requires an application/web server. But, Mine is a Core Java application.
    I don't know much about shared DB. Please refer some Links wherein I can find the efficiency of this method.


    Regards,
    Namrata
    NamrataS Sinha
    Greenhorn

    Joined: Feb 19, 2012
    Posts: 6
    Ram Narayan.M wrote:If simply want two JVMs to be communicated, RMI is the best option.

    "Socket Programming" is a raw mode which has to be dealt very carefully.



    Hi,

    Thanks for the reply.
    Yes , socket programming is very raw form of communication in comparision with RMI.
    But as my question is which method is the efficient one?
    Please suggest.

    Regards,
    Namrata Sinha
    NamrataS Sinha
    Greenhorn

    Joined: Feb 19, 2012
    Posts: 6
    William Brogden wrote:Another high level communication approach is JMS Java Message Service - which requires a separate JMS server but has the great advantage of being asynchronous.

    Direct socket programming / RMI and web services require that both JVMs work together.

    Shared DB, shared file, JMS permit one JVM to drop off information which the other can pick up as it is convenient.



    Given that Java was developed by a company whose slogan was "the network is the computer" it is not surprising to find so many communication methods.

    Bill



    Hi Bill,

    Thanks a lot for your reply.
    My application is a Core Java application. Is JMS suitable for it? I mean the JMS reuires a JMS server which is a part of EE server. Then is it suitable for my app?

    I also didn't understand the below line :-
    Direct socket programming / RMI and web services require that both JVMs work together. Please elaborate..

    Yes Java has lots of method of communication between JVM to JVM. But, I want the method that runs for Core Java app . So please suggest such methods.


    Regards,
    Namrata
    NamrataS Sinha
    Greenhorn

    Joined: Feb 19, 2012
    Posts: 6
    Bhanuprakash Sreenivas wrote:
    You need to be more specific about your needs.
    Like if it is a critical application , JMS would be a good choice.

    Other options,

    1. Avoid serialization since it will have compatibility issues .
    One lightweight alternative you can explore is Google Protocol Buffers.

    2 . Using a JMS should be an ideal choice based on how robust you want your applications to be.
    But you need to keep in mind the following.
    - Heavyweight , since it will be yet another process inbetween the two JVM process
    - Need to use transactions to make it perfect.

    3 . Expose as a webservice .


    Hi,

    Thanks for your reply.

    Yes my application is a critical one. But can JMS be used for a stand-alone application? Please give me some reference that gives example of running JMS for non-enterprise applications.

    Again web -services doesn't seem the solution.
    Please suggest.

    Regards,
    Namrata Sinha

    William Brogden
    Author and all-around good cowpoke
    Rancher

    Joined: Mar 22, 2000
    Posts: 12778
        
        5
    1. You don't need to buy into the full JEE to get a JMS server - see the Apache ActiveMQ project and many other open source implementations.

    2. An important distinction.
    I also didn't understand the below line :-
    Direct socket programming / RMI and web services require that both JVMs work together. Please elaborate..


    For direct socket, etc. both JVMs must be devoting CPU cycles at the same time. A transmitting socket MUST have an active receiving socket. etc.

    Socket to socket will always be the fastest - harder to write or alter, harder to debug, but fastest.

    Bill
    NamrataS Sinha
    Greenhorn

    Joined: Feb 19, 2012
    Posts: 6
    William Brogden wrote:1. You don't need to buy into the full JEE to get a JMS server - see the Apache ActiveMQ project and many other open source implementations.

    2. An important distinction.
    I also didn't understand the below line :-
    Direct socket programming / RMI and web services require that both JVMs work together. Please elaborate..


    For direct socket, etc. both JVMs must be devoting CPU cycles at the same time. A transmitting socket MUST have an active receiving socket. etc.

    Socket to socket will always be the fastest - harder to write or alter, harder to debug, but fastest.

    Bill


    Hi Bill,

    Thanks a lot for such a comprehensive reply.
    It is very much helpful.



    Regards,
    Namrata Sinha
    Jimmy Clark
    Ranch Hand

    Joined: Apr 16, 2008
    Posts: 2187
    A web service is used to connect distributed applications. This is the modern method of distributed computing and does not require an application server or a web server. See Axis for more details http://ws.apache.org/axis/java/user-guide.html
    kien kun
    Greenhorn

    Joined: Feb 15, 2012
    Posts: 27
    RMI,which is called remote computers.
    TCP/UDP Socket is transplanted between more computer in the network
    The Java Message Service (JMS) API is a Java Message Oriented Middleware for sending messages between two or more clients.
    CORBA is a mechanism in software for normalizing the method-call semantics between application objects residing either in the same address space (application) or remote address space (same host, or remote host on a network).
    Nicolo Villarete
    Greenhorn

    Joined: Mar 20, 2012
    Posts: 7

    If it's JVM to JVM I would also go for RMI.
    Tim Moores
    Rancher

    Joined: Sep 21, 2011
    Posts: 2408
    The problem with RMI is that it generally relies on both sides using the same JVM version, which is a rather unpractical requirement. I don't understand why anyone would use RMI these days when web services are so easily implemented.
    Pat Farrell
    Rancher

    Joined: Aug 11, 2007
    Posts: 4655
        
        5

    Nicolo Villarete wrote:If it's JVM to JVM I would also go for RMI.

    Using RMI usually adds far more problems to any solution. Its a poor solution in general. I have not seen a good use for RMI this century.
    Nick Stavros
    Greenhorn

    Joined: May 18, 2013
    Posts: 3
    Another solution is to use a Object Management Group (OMG) Standard Data Distribution Serves (DDS). See the wikipedia entry for DDS: Data Distribution Service (DDS)

    I like this solution because:

  • It is a standard based solution that standardized the APIs as well as the data format for marshaling the data
  • It can be used within the same box or across different boxes just by changing the configuration
  • It is a many-to-many publish-subscribe paradigm
  • It is scalable to many publishers and subscribers
  • It can be configured for durability )i.e., store data to a DB
  • It can be configured to reliable deliver messages allowing asynchronous publish-subscribe
  • There are over a dozen vendors including open source providers that have demonstrated interoperability between themselves
  • It works on multiple hosts OSs (UNIX, Linux, Windows)
  • It works with numerous languages (Java, C/C++, C#, etc) so it can be used to connect differed codebases
  • There is a developing standard (i.e., summer of 2013) for support of RESTful interfaces
  • There is support for Microsoft Office including Excel, PowerPoint) which allows you to use the published data from within these products too.
  • It is extremely fast and can support real-time solutions (i.e., 100,000+ messages a second)
  • You simply link in a .so or .dll to your code on each publisher and subscriber ... NO SERVERS REQUIRED

  •  
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: JVM to JVM Communication