Java Interprocess Communication

谁都会走 提交于 2019-12-18 05:14:16

问题


I have a situation where i need to send commands to a running java application, now i am using tcp/ip socket to send commands to the application using a internet explorer context menu item. But as soon as the application starts virus scanners complain that the application started listening, although i am only listening for local connections. I think this may be confusing to the users. I am looking at others ways of communicating without pissing off av scanners?


回答1:


For this, you're best off a file based FIFO queue. Or using Java Native Access/Java Native Interface to write to a NamedPipe or Shared Memory. If you go the JNA/JNI route, you could create a Named Event.

But there's probably no way to do what you want, with any amount of efficiency without going the JNA/JNI route.




回答2:


You can use Java Management Extentions (JMX) to expose methods in a running process through a simple web interface.




回答3:


Sockets are pretty much the traditional way of doing IPC, but if you really want to avoid them, you might be able to come up with a workaround using the local filesystem. You wouldn't want to use standard file reads/writes, since you would most likely want to effectively implement a queue in the filesystem.

If I were going to implement IPC through the filesystem, I'd probably use SQLite (which can be threadsafe when compiled so) and have one table for each listener. I'd probably use a single-column table to insert the message, and the listener would just pull out the row with the lowest rowid, then delete said row.

But my approach is not at all Java-specific, so there might be better ways to do that using Java (such as @darthcoder's response).




回答4:


A lot of folks use something like JMS in this scenario.



来源:https://stackoverflow.com/questions/1416780/java-interprocess-communication

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!