我的RMI实践

来源:互联网 发布:linux ibus rime配置 编辑:程序博客网 时间:2024/05/22 05:11
<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 PerfectTimeReady to do timeF:/rmi>javac *.javaF:/rmi>rmic PerfectTimeF:/rmi>start rmiregistryF:/rmi>java PerfectTimeReady to do time另开一DOS窗口F:/rmi>java -Djava.security.policy=registerit.policy DisplayPerfectTimePerfect time = 1011585443953Perfect time = 1011585443968Perfect time = 1011585444000Perfect time = 1011585444000Perfect time = 1011585444015Perfect time = 1011585444031Perfect time = 1011585444031Perfect time = 1011585444046Perfect time = 1011585444062Perfect time = 1011585444062注意:如果在rmic PerfectTime时报找不到PerfectTime类,请在环境变量中的ClassPath中加入:F:/rmi
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 qq说明 qq输入法 qq如何分组好友 qq分组名称简单好听 qq怎么注销账号 邮箱qq登陆 情侣网民 qq新用户注册 qq客户端 qq密码找回不用申诉 怎样创qq号 qq怎么申诉 忘记qq号码怎么找回 怎样盗qq号 q网 qq聊天下载 qq分组名字 qq铃声下载 qq 申诉 下载qq聊天软件 qq看点怎么关闭 qq透明皮肤 手机qq网页在线登陆 qq安全中心网页版 qq2016版下载 盗qq密码软件 手机注册qq qq照片 qq群群发软件 qq密码和账号 qq空間 qq空白昵称 qq影像 qq主页 下载天天飞车 手机qq网页 qq聊天软件 技术qq网 qq手机登录 qq皮肤下载 手机密保