• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Communication Between Java Programs

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got a design problem, and I am looking for possible solutions.

I have two Java programs running on one computer. I would like to keep the programs packaged separately, but I would like to call a few select methods of each program from the other. (Program #1 calls Mehtods A, B, and C from Program #2, while Program #2 calls methods D, E, and F from Program #1.)

I know there is an official Java package to communicate over a network, but that might be a little overkill, since both programs are running on the same computer. I don't think JINI would be appropriate either, because all my methods calls will be in Java. Niether would RMI be appropriate, because I'm using the same virtual machine. Any suggestions? Do I need something home grown here? This may be so simple that I'm just overlooking it.

Landon
 
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are running 2 Java programs, then both of them are running in seperate instances of Java. In all practical aspects, both of them are running in differrent Virtual Machines, just as if they were running on seperate computers. All classes and variables will be loaded seperately

Your options in this case are
a) RMI
b) Sockets
c) using shared Files/database to pass data- this option is messy, hence not reccomended

Why do you want your apps to talk to each other? Do you just want to reuse code, or do you really want to pass data between apps? If you just want to reuse code, I would suggest packaging your reusable classes in seperate jars, and using the jars in both apps
 
Landon Blake
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jayesh,

Thank you for your response. I want to transfer data and call mathods of both programs. In fact, I'd like to pass an object contained in one program as the argument to the method in the other program. I know I could facilitate this by parsing an XML file representing my request and the object, but ould RMI be the best?

Landon
reply
    Bookmark Topic Watch Topic
  • New Topic