在Windows/Unix-like平台中,针对 IPC (Inter-process Communication)提供了许多机制,例如 Semaphore, Pipe, Shared memory等。在Java中,这些强大的能力都受到了限制,由于Java本身是提供Thread机制的,所以线程间是不大需要考虑使用IPC的,但是有时候Java应用程序可能需要同其它的native application进行通信,这种情况下就需要考虑IPC方式了。 Socket当然是可选方案之一,不过很多时候由于需要通信的数据并不多,采用socket就有点算weight solution了。RMI和Socket就不放在考察范围之内。 遗憾的是,根据google查到的资料,并没有发现非常简洁优雅的解决方案——最raw的就是用JNI了,遇到这种需要维护C、C++指针的情况,crash掉整个JVM的bug是必然多发的。查了一些资料,愈发无奈…… 难道真的要靠自己搞定JNI,或是购买成熟的commercial product来解决?? I am familiar and had used many times concurrent threads and "synchronized" in Java. The thing is, I want to share memory between 2 threads/processes , one in Java and one in "C". There is of course the JNI solution; I am currently using it; the thing is that when you call a JNI method from Java , and there is some problem in the "C" code (like a pointer which is not handled right and ,for example, is incremented so that it points to a non-valid address) it is sometimes difficult to trace. Of course you c...