我正在尋找Java中的進程間通信庫。我期待在JVM之間發送小消息,並且如果可能的話,我希望使用共享內存。inter jvm communication
7
A
回答
2
我建議你看看Terracotta。我不知道它是否符合你的要求,因爲Terracotta的主要目標是無縫的可擴展性(「api」只是內存訪問),但它肯定有消息集成模塊。它是開源的。
乾杯。
11
Java NIO支持內存映射文件。如果多個JVM存儲器映射相同的文件,則可以將其用作共享內存。
這裏是內存映射文件的一個例子。
try {
int shmSize = 1024;
RandomAccessFile file = new RandomAccessFile("shm.raw","rw");
// inialize file size
if(file.length() < shmSize) {
byte[] tmp = new byte[shmSize];
file.write(tmp);
file.seek(0); // seek back to start of file.
}
// memory-map file.
FileChannel ch = file.getChannel();
MappedByteBuffer shm = ch.map(FileChannel.MapMode.READ_WRITE, 0, shmSize);
ch.close(); // channel not needed anymore.
shm.load(); // force file into physical memory.
// now use the ByteBuffer's get/put/position methods to read/write the shared memory
} catch(Exception e) { e.printStackTrace(); }
在Linux上,您可以在/ dev/shm/a基於內存的文件系統中創建shm.raw文件。這將有助於避免任何磁盤I/O。
欲瞭解更多詳情請閱讀這篇文章Introduction to Memory-Mapped IO in Java
你也仍然需要一種方法來syncronize讀取/寫入共享內存。當一個完整的消息被寫入時,發送者JVM將需要發信號給接收者JVM。
使用Java NIO的SocketChannel對於小消息可能會更好,因爲收到消息時可以通知接收者。共享內存只有在發送大量消息時纔有用。
對於JVM之間IPC在不同機器上嘗試 JIPC
+1
對於機器間,我使用JGroups或來自通信的套接字,並且對於JVM內的隊列起作用。我的通信組件中的孔在同一臺機器上是進程間的。 – Javamann 2009-05-01 08:32:44
相關問題
- 1. Websockets可以與Inter Process Communication結合嗎?
- 2. Inter-Communication(服務控制器指令)
- 3. android inter inter com無分享
- 4. Angular 2:contentChildren communication
- 5. javascript to asp.net communication
- 6. Android Activity Service Communication
- 7. Jade Two Agents communication
- 8. MVP:Presenter-Model communication
- 9. Golang TCPConn Gob Communication
- 10. Actionscript Class Communication
- 11. Windows Communication Foundation(WCF)
- 12. durandal.js viewmodel communication
- 13. Node.js/SignalR Communication
- 14. Cross View Communication
- 15. UWP IPC:background-> foreground communication
- 16. Inter小程序通信
- 17. Inter-AppDomain通信問題
- 18. Coldfusion 9 Inter portlet通信?
- 19. Inter Components與React的通信
- 20. CreateFile with Serial communication has access violation
- 21. Web API vs Window Communication Foundation
- 22. .com.mysql.jdbc.exception.jbbc4.communicationexception..communication鏈接失敗
- 23. Java/C#Kerberos inter-op可能嗎?
- 24. 我如何閱讀Window Communication Foundation(WCF)
- 25. 什麼樣的Webservice-Communication-Technologies可用?
- 26. Cordova跨域文件:// iframe contentwindow communication
- 27. Windows Communication Foundation - .NET Framework的哪個版本?
- 28. Inter-Webservice通信是否有良好的框架/模式/等?
- 29. tsc不被識別爲inter。或分機。命令
- 30. (inter portlet通信)liferay 6.0.5和JSF1.2中的IPC
我看了看兵馬俑,但是它是對於這個問題一個非常沉重的解決方案。 Thx – Javamann 2009-05-01 19:15:33