📄 16u.txt
字号:
// PerfClient.java
import java.util.*;
public class PerfClient {
public static void main(String[] args) throws Exception {
javax.naming.Context context = new javax.naming.InitialContext();
Object ref = context.lookup("accounts/savings");
AccountHome savingsHome =
(AccountHome) javax.rmi.PortableRemoteObject.narrow(ref, AccountHome.class);
ref = context.lookup("accounts/checking");
AccountHome checkingHome =
(AccountHome) javax.rmi.PortableRemoteObject.narrow(ref, AccountHome.class);
Account peter = savingsHome.create("Peter", 200f);
Account paul = checkingHome.create("Paul", 100f);
System.out.println("Peter's balance: " + peter.getBalance());
System.out.println("Paul's balance: " + paul.getBalance());
ref = context.lookup("teller");
TellerHome tellerHome =
(TellerHome) javax.rmi.PortableRemoteObject.narrow(ref, TellerHome.class);
Teller teller = tellerHome.create();
System.out.println("Taking from Peter and giving to Paul");
{
long begin = System.currentTimeMillis();
for(int i = 0; i < 100; i++)
{
teller.transfer(peter, paul, 1f);
}
long end = System.currentTimeMillis();
System.out.println("Time per transaction: " + ((end - begin) / 100f) + "mS");
}
teller.remove();
System.out.println("Peter's balance: " + peter.getBalance());
System.out.println("Paul's balance: " + paul.getBalance());
peter.remove();
paul.remove();
}
}