Web服务-客户端服务实例化 [英] Webservice - client service instantiation

查看:229
本文介绍了Web服务-客户端服务实例化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道创建Web服务客户端服务实例的成本是多少吗?

Do you know how costly is to create a webservice client service instance ?

 JavaWebService service = new JavaWebService();
 SomePort port = service.getJavaWebServicePort(); 

在多线程环境(webapp)中重用同一端口一次又一次创建服务并不危险吗?

Creating the service once and after that reusing same port in a multi threaded environment (webapp) is not dangerous ?

请阅读端口getPort和端口本身不是线程安全的,但是每次创建服务时,如果这是一项昂贵的操作,则可能会出现问题.

Read that the port getPort and port itself is not thread safe but also creating each time a service it might be problematic if it is a costly operation.

有什么主意吗?

谢谢

推荐答案

在JAX-WS参考实现(Metro)中,JavaWebService的创建是廉价的(在生成的客户端中,我们倾向于发现这种情况20ms).

In the JAX-WS reference implementation (Metro), the creation of the JavaWebService is inexpensive (in our generated clients, we tend to find this takes around 20ms).

SomePort的首次创建非常昂贵(对我们来说大约200毫秒);随后在同一JavaWebService实例上调用getSomePort()的速度要快得多(对我们来说大约3ms).

The first creation of SomePort is quite expensive (circa 200ms for us); subsequent calls to getSomePort() on the same JavaWebService instance are substantially quicker (circa 3ms for us).

因此,每次需要获取SomePort时创建一个JavaWebService的实现都会带来一定程度的费用.简而言之,问题的答案是相当昂贵".

So, an implementation that creates a JavaWebService every time it needs to get a SomePort will carry a degree of expense. In short, the answer to the question is "Quite costly".

但是,即使SomePort上的方法不是线程安全的,但JavaWebService上的方法也是.因此,明智的使用模式(至少对于Metro来说是这样的(至少由于规格欠缺,线程安全是特定于实现的))是重用JavaWebService,因为您只会产生一次昂贵的getSomePort()调用.

However, even though the methods on SomePort are not thread safe, the methods on JavaWebService are. So, the sensible usage pattern (at least with Metro - thread-safety is implementation specific due to a somewhat lacking specification) is to reuse JavaWebService as you will only incur the expensive getSomePort() call once.

更新

这与Oracle德国员工Andreas Leow的两篇帖子相吻合,这是@PapaLazarou在下面的评论中引用的帖子中的发帖人之一,他写了关于Service对象的内容,

This agrees with two posts by Andreas Leow, an employee from Oracle Germany, one of the posters in the thread referenced by @PapaLazarou in the comment below, who wrote regarding the Service object,

每个WSDL只能创建一个静态Service实例:任何单个Service对象都是完全线程安全的,并且可以由任意多个并发线程共享.

You can create just one single static Service instance per WSDL: any single Service object is fully thread-safe and can be shared by as many concurrent threads as you like.

以及端口的使用情况,

尽管我几乎100%可以肯定CXF JAX-WS端口是线程安全的,但Metro的Port对象肯定不是线程安全的.

While I am almost 100% certain that CXF JAX-WS Ports are thread-safe, Metro's Port objects definitely are not thread-safe.

这篇关于Web服务-客户端服务实例化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆