开发者

How to communicate with existing java process

How can I pa开发者_StackOverflow社区ss some values from a shell script to a Java program that is already running?


Standalone Java application is already running, so command line parameters are out of question.

Simplest alternatives remaining are polling for files, sockets and HTTP server.

Polling for files:

Make you java app to read a specific directory once in a few seconds. If a file appears in that directory, read it and do as it says. Make your shell script to form that file.

Socket:

Make you java app to listen on a socket. Use netcat or a similar utility to send commands to that socket.

HTTP Server:

Start an HTTP listener within the Java process. Use wget or similar utility to post your commands to that listener:

HttpServer httpServer = HttpServer.create(new InetSocketAddress(port), 5);
httpServer.createContext("/", new TileServerRequestHandler());
httpServer.setExecutor(Executors.newCachedThreadPool());
httpServer.start();


Write the params to a file that your process interrogates periodically? Crude, but it'd work ( but with a lot of usage limitations ). Or have your process listen on a socket and get your shell script to send the parameters down the socket.


One option for communicating with a Java process is the Java Messaging Service API. Your shell script could launch a JMS client to send messages to the main application.


See how to pass command line parameters to java here

EDIT: new information in the question means this is no longer a suitable solution

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜