我的RMI实践

<script type="text/javascript"> google_ad_client = "pub-8800625213955058"; /* 336x280, 创建于 07-11-21 */ google_ad_slot = "0989131976"; google_ad_width = 336; google_ad_height = 280; // </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> 注:本文所涉及代码转自thinking in java ,但有改动 四个文件: //: c15:rmi:PerfectTime.java // From 'Thinking in Java, 2nd ed.' by Bruce Eckel // www.BruceEckel.com. See copyright notice in CopyRight.txt. // The implementation of // the PerfectTime remote object. import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; import java.net.*; public class PerfectTime extends UnicastRemoteObject implements PerfectTimeI { // Implementation of the interface: public long getPerfectTime() throws RemoteException { return System.currentTimeMillis(); } // Must implement constructor // to throw RemoteException: public PerfectTime() throws RemoteException { // super(); // Called automatically } // Registration for RMI serving. Throw // exceptions out to the console. public static void main(String[] args) throws Exception { PerfectTime pt = new PerfectTime(); Naming.rebind("/PerfectTime", pt); System.out.println("Ready to do time"); } } ///:~ //: c15:rmi:PerfectTimeI.java // From 'Thinking in Java, 2nd ed.' by Bruce Eckel // www.BruceEckel.com. See copyright notice in CopyRight.txt. // The PerfectTime remote interface. import java.rmi.*; interface PerfectTimeI extends Remote { long getPerfectTime() throws RemoteException; } ///:~ //: c15:rmi:DisplayPerfectTime.java // From 'Thinking in Java, 2nd ed.' by Bruce Eckel // www.BruceEckel.com. See copyright notice in CopyRight.txt. // Uses remote object PerfectTime. import java.rmi.*; import java.rmi.registry.*; public class DisplayPerfectTime { public static void main(String[] args) throws Exception { System.setSecurityManager( new RMISecurityManager()); PerfectTimeI t = (PerfectTimeI)Naming.lookup("/PerfectTime"); for(int i = 0; i < 10; i ) System.out.println("Perfect time = " t.getPerfectTime()); } } ///:~ grant { // Allow everything for now permission java.security.AllPermission; }; 存入于F:/rmi下 操作步骤 F:/rmi>java PerfectTime Ready to do time F:/rmi>javac *.java F:/rmi>rmic PerfectTime F:/rmi>start rmiregistry F:/rmi>java PerfectTime Ready to do time 另开一DOS窗口 F:/rmi>java -Djava.security.policy=registerit.policy DisplayPerfectTime Perfect time = 1011585443953 Perfect time = 1011585443968 Perfect time = 1011585444000 Perfect time = 1011585444000 Perfect time = 1011585444015 Perfect time = 1011585444031 Perfect time = 1011585444031 Perfect time = 1011585444046 Perfect time = 1011585444062 Perfect time = 1011585444062 注意:如果在rmic PerfectTime时报找不到PerfectTime类,请在环境变量中的ClassPath中加入:F:/rmi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值