ResearchClient.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package bible.ejb.session.example1;
- import java.rmi.*;
- import java.util.*;
- import javax.naming.*;
- /**
- * ResearchClient periodically asks server for research.
- */
- public class ResearchClient extends TimerTask implements Runnable {
- private Random rand = new Random();
- private String[] securities = null;
- /**
- * Initializes an InitialContext, gets a reference to a remote EJB on the server,
- * and asks that EJB for research.
- */
- public void run() {
- System.out.println("ResearchClient calling remote EJB.");
- System.out.println(" Time: " + new Date(System.currentTimeMillis()));
- try {
- InitialContext ctx =
- Environment.getInitialContext();
- Object objref =
- ctx.lookup("RequestResearch");
- RequestResearchHome home =
- (RequestResearchHome) javax.rmi.PortableRemoteObject.narrow(objref,
- RequestResearchHome.class);
- RequestResearchRemote requestResearchBean = home.create();
- StringBuffer sb = new StringBuffer();
- sb.append(requestResearchBean.requestResearch("YHOO") + "n");
- sb.append(requestResearchBean.requestResearch("BEAS") + "n");
- sb.append(requestResearchBean.requestResearch("WAG") + "n");
- System.out.println(sb.toString());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Declare a new client and schedule it on a timer.
- */
- public static void main(String[] args) {
- Timer t = new Timer();
- ResearchClient client = new ResearchClient();
- // Starting in 5 secs, run every 5 seconds.
- t.schedule(client, 5000, 5000);
- }
- }
- /*--- Formatted in Bible Style on Thu, Sep 6, '01 ---*/
- /*------ Formatted by Jindent 3.24 Gold 1.02 --- http://www.jindent.de ------*/