public static void invokeMethod1() {
long s=new Date().getTime();
UserServiceImplService serivce = new UserServiceImplService();
UserServiceImpl impl = serivce.getUserServiceImplPort();
User u = new User();
impl.addUser(u);
long s1=new Date().getTime();
System.out.println(s1-s);
//第一次去调用1297
//1437 1062 1063 1078 1047
}
public static void invokeMethod2() {
long s=new Date().getTime();
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("http://localhost:8088/abc");
QName SERVICE = new QName("http://liaomin", "UserServiceImplService");
factory.setServiceName(SERVICE);
factory.setServiceClass(UserService.class);
UserService us = (UserService) factory.create();
User u = new User();
// us.addUser(u);
us.addUser(u);
long s1=new Date().getTime();
System.out.println(s1-s);
//第一次去调用1265
//1047 1047(比较稳定)
}
public static void invokeMethod3() throws MalformedURLException {
long s=new Date().getTime();
QName SERVICE = new QName("http://liaomin", "UserServiceImplService");
QName UserServiceImplPort = new QName("http://liaomin", "UserServiceImplPort");
URL url = new URL("http://localhost:8088/abc?wsdl");
ServiceDelegate dele=Provider.provider().createServiceDelegate(url,SERVICE,Service.class);
UserService us = (UserService) dele.getPort(UserServiceImplPort,UserService.class);
User u = new User();
us.addUser(u);
long s1=new Date().getTime();
System.out.println(s1-s);
//第一次去调用 1281
//1047 1031 1047 1016 1032
}
public static void invokeMethod4()
{
long s=new Date().getTime();
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(UserService.class);
factory.setAddress("http://localhost:8088/abc");
// factory.getServiceFactory().setDataBinding(new AegisDatabinding());
UserService client = (UserService) factory.create();
User u = new User();
client.addUser(u);
long s1=new Date().getTime();
System.out.println(s1-s);
//第一次去调用 1188
//调用一次后 1016 1000 1016 1015
}
通过实践去测试 只有第四种调用耗费的时间最少的
如果在频繁取数据的系统中 能优化100ms的速度 对性能就会有大大的提高
比如我调用 100次webservice发送消息 每发送一次 是 1200ms(1.2s) 总共耗时 120s
如果采用第四种 只需要 1000ms(1s) 总共耗时 100s 那么优化了20s时间 20s是个什么概念
假如是调用 1000 10000次发送了 优化的效率就更大