tags:

views:

108

answers:

6

Hi,

I am writing a program that starts another java process which runs certain code. Is there any way I can "talk" to that process to call methods of the running class(es)?

+5  A: 

You're going to have to use some form of remoting. That could be:

  • RMI;
  • Web Services (JAX-WS, Spring Web Services, etc);
  • Sockets;
  • Embedded Web container;
  • etc.
cletus
+1  A: 

They will be able to communicate via pipes or sockets. You either create your own communication protocol over it, or use something like RMI.

Zed
A: 

RMI is a simple Java remoting technology. Of itself it doesn't address issues that tend to surface when you go for large-scale client and server scenarios, such as failover in the event of errors.

Hence the usual pattern when requiring something a bit stronges is to use some "App Server" kind of technology on the server side. You can knock up remotely accessible services quite quickly using frameworks such as EJB 3 or Spring, or you can use technlogies such as JMS.

My recomendation would be to bite the bullet and go beyond RMI immediately, these days the maturity of the App Servers and frameworks, and the availability of low cost and free App Servers makes the cost of entry pretty low.

djna
A: 

Another approach is Jini.

Pete Kirkham
A: 

There's a whole class of solutions referred to as IPC, Inter-Process Communication. These range from shared memory and pipes, to network communication and remote procedure frameworks. In java you have a variety of solutions to each of these. If you're familiar with networks already, you can pass messages that way, otherwise you might want to setup asynchronous message queues or pipes, you'll likely find shared memory being prone to bugs, and remote procedures like JINI being too complicated to setup and maintain.

dlamblin
A: 

One more solution, albeit not that trivial, is JMS. If the nature of the communication is mostly to pass information or small objects, this could be useful.

Yuval