老师说我是创建对象的时机有问题,导致运行起来比较慢,谁可以具体帮我看下什么问题:
第一个:
public class DummyClient {
/** トレース */
private ServerTraceLog traceLog;
private ClientIF cif;
/**
* RMIServer の lookupします.
* @param ip string
* @param port string
**/
public void lookupRMIServer(String ip,String port) {
traceLog = new ServerTraceLog();
//Method Start Trace
traceLog.logDebug(3, ComFix.STA);
traceLog.logAPL("lookuoRMIServer called to start");
traceLog.logDebug(1, "======= lookuoRMIServer input parameter =======");
traceLog.logDebug(1, "ip" + "--->" + ip);
traceLog.logDebug(1, "port" + "--->" + port);
try {
cif = (ClientIF)Naming.lookup( ip + port + "/Rncinfo");
if (cif == null){
traceLog.logDebug(1, "cif is null");
}
} catch(Exception e){
System.out.println("#Fail# rmiServerLookup:"+e);
traceLog.logDebug(1, "rmiServerLookup failed");
}
//Method End Trace
traceLog.logAPL("lookuoRMIServer called to end");
traceLog.logDebug(3, ComFix.END);
}
/**
* Rncの情報を取得します。
* @param rncInfo
* @return ret
**/
public RncInfo[] getRncRelatedMOIInfo(RncInfo rncInfo){
traceLog = new ServerTraceLog();
//Method Start Trace
traceLog.logDebug(3, ComFix.STA);
traceLog.logAPL("getRncRelatedMOIInfo called to start");
traceLog.logDebug(1, "======= getRncRelatedMOIInfo input parameter =======");
traceLog.logDebug(1, "rncInfo" + "--->" + rncInfo);
RncInfo[] ret = null;
//objectはnullが発生した場合
if (cif == null) {
System.out.println("the object is null!");
System.exit(1);
traceLog.logDebug(1, "getRncRelatedMOIInfo failed");
}
try {
traceLog.logDebug(1, "start call!");
ret = cif.getRncRelatedMOIInfo(rncInfo);
} catch ( Exception ex ) {
ex.printStackTrace();
traceLog.logDebug(1, "getRncRelatedMOIInfo failed");
}
//Method End Trace
traceLog.logAPL("lookuoRMIServer called to end");
traceLog.logDebug(3, ComFix.END);
return ret;
}
public static void main(String[] args) {
RncInfo rncinfo=new RncInfo();
RncInfo[] returnInfo;
rncinfo.para1=1.8f;
rncinfo.para2=9;
DummyClient dummyClient1=new DummyClient();
dummyClient1.lookupRMIServer( "rmi://localhost:","1098");
returnInfo=dummyClient1.getRncRelatedMOIInfo(rncinfo);
if (returnInfo != null && returnInfo.length > 1) {
System.out.println("the return info: number1->"+returnInfo[0].para1);
System.out.println("the return info: number2->"+returnInfo[0].para2);
System.out.println("the return info: number3->"+returnInfo[1].para1);
System.out.println("the return info: number4->"+returnInfo[1].para2);
}else{
System.out.println("returnInfo ERRORの場合");
}
}
}