Do you know how costly is to create a webservice client service instance ?
JavaWebService service = new JavaWebService();
SomePort port = service.getJavaWebServicePort();
Creating the service once and after that reusing same port in a multi threaded environment (webapp) is not dangerous ?
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.
Any idea ?
THanks
In the JAX-WS reference implementation (Metro), the creation of the
JavaWebServiceis inexpensive (in our generated clients, we tend to find this takes around 20ms).The first creation of
SomePortis quite expensive (circa 200ms for us); subsequent calls togetSomePort()on the sameJavaWebServiceinstance are substantially quicker (circa 3ms for us).So, an implementation that creates a
JavaWebServiceevery time it needs to get aSomePortwill carry a degree of expense. In short, the answer to the question is “Quite costly”.However, even though the methods on
SomePortare not thread safe, the methods onJavaWebServiceare. So, the sensible usage pattern (at least with Metro – thread-safety is implementation specific due to a somewhat lacking specification) is to reuseJavaWebServiceas you will only incur the expensivegetSomePort()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
Serviceobject,and about the usage of ports,