Frage

Is it possible that a java program is running and it works on commands from another java program simultaneously running in same machine? For example: if a second java program sends a query database command to first running java program, the first one will execute a query in the database connected to it and reply back to second one.

Please help.

Thanks in advance.

War es hilfreich?

Lösung

You could use socket programming to do this. Make a server and make it listen to incoming messages.

http://docs.oracle.com/javase/tutorial/networking/sockets/

You could learn about sockets from the above link.

Andere Tipps

It is possible.

Socket programming is good but in this case you have to implement synchronization and multi threading request handling.

Another way is using web service for storing data in db. http://docs.oracle.com/javaee/6/tutorial/doc/gijvh.html

Probably you can use any of remote invocations (RMI), see http://docs.oracle.com/javase/tutorial/rmi/ or manged beans (JMX), see http://docs.oracle.com/javase/tutorial/jmx/

As already answered you can use socket proramming but you would have to implement your own protocol.

It should be easier to use RMI which lets you invoke remote methods as if they were local but it is limited to java.

A "bit" heavier (in resources and implementation) solution is using web services but it is a standard which is not limited to java world.

You can also use JMS but I think it should be overkill (you need a server such as activeMQ)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top