Webservice - client service instantiation

╄→尐↘猪︶ㄣ 提交于 2019-12-03 06:21:09

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).

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).

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".

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.

Update

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,

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.

and about the usage of ports,

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

If you are using jax-ws, then you cannot share a port across threads (they are not thread-safe). if you are concerned about the overhead of creating a port (and have measured it and confirmed that it is a bottleneck in your application), then you could create a connection pool of ports.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!