public class RpcHessianClient {
public static void main(String[] args) {
String url = "http://localhost:8081/apis/hello";
HessianProxyFactory factory = new HessianProxyFactory();
ExecutorService es = Executors.newFixedThreadPool(10);
int size = 1000000;
final CountDownLatch cdl = new CountDownLatch(size);
try {
long start = System.currentTimeMillis();
factory.setUser("client1");
factory.setPassword("client1");
factory.setOverloadEnabled(true);
final Hello basic = (Hello) factory.create(Hello.class,
url);
for (int i = 0; i < size; i++) {
es.submit(new Runnable() {
@Override
public void run() {
String u=basic.hello("guolei");
//System.out.println(u);
cdl.countDown();
}
});
}
cdl.await();
long time = System.currentTimeMillis() - start;
System.out.println("SayHello:");
System.out.println("耗时:" + (double) time / 1000 + " s");
System.out.println("平均:" + ((double) time) / size +" ms");
System.out.println("TPS:" + (double) size / ((double) time / 1000));
// System.out.println("Hello, " + s.getMail());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
es.shutdown();
}
}
|