Cajo的目的就是使得JVM间的通信变得简单,不需要EJB容器,任何servlet容器之间都可以进行通信。先到官方网站http://java.net/projects/cajo/downloads 下载相应的包,就一个包下载完就可以直接用了。

只需要用到gnu.cajo.invoke.Remote和gnu.cajo.utils.ItemServer两个类就可以了,如下:

Remote.config(null, port, null, 0);
ItemServer.bind(new CajoTestObj(), "displayMethodName");

如果另一台JVM需要读取相关信息的话可以这样:

Object object = Remote.getItem("//host:port/displayMethodName");
Map<Integer, User> userArray= (Map<Integer, User>)Remote.invoke(object, "realMethodName",null);

就这么简单就读取到了另外一台JVM上的数据。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐