When you use javax.xml.ws.Endpoint.publish to handle incoming restful/soap requests, will it generate a thread for each request? or will I have handle threads myself?
I've been trying to work this out for a couple of days now. The documentation hints on threads, but there is nothing specific about this.
Doc says:
An Executor may be set on the endpoint in order to gain better control over the threads used to dispatch incoming requests. For instance, thread pooling with certain parameters can be enabled by creating a ThreadPoolExecutor and registering it with the endpoint.
For me that looks like it handles threads, but you will have no control over them, so adding a ThreadPoolExecutor to execute the threads, you will have a pool of threads you can work with. Is this right?
Uses of Endpoint in javax.xml.wsCreates an endpoint with the specified binding type, implementor object, and web service features. Creates and publishes an endpoint for the specified implementor object at the given address. Creates and publishes an endpoint for the specified implementor object at the given address.
The BindingProvider interface provides access to the protocol binding and associated context objects for request and response message processing.
Java API for XML Web Services (JAX-WS) is a technology for building web services and clients that communicate using XML. JAX-WS allows developers to write message-oriented as well as Remote Procedure Call-oriented (RPC-oriented) web services.
Examining section 5.2.7 of the JavaTM API for XML-Based Web Services specification (JAX-WS) seems to indicate so, although it looks like there is some room for implementation specific behavior. To really know what is going on you'd have to investigate the JAX-WS implementation you are using and the particular deployment environment. I'd imagine the behavior might be different depending upon whether the service is deployed within a Servlet container or in a standalone process. The control that you do have over the threads is limited to providing a specific ThreadPoolExecutor
implementation. Section 5.2.7 states:
5.2.7 Executor
Endpoint
instances can be configured with ajava.util.concurrent.Executor
. The executor will then be used to dispatch any incoming requests to the application. ThesetExecutor
andgetExecutor
methods ofEndpoint
can be used to modify and retrieve the executor configured for a service.<> Conformance (Use of Executor): If an executor object is successfully set on an
Endpoint
via thesetExecutor
method, then an implementation MUST use it to dispatch incoming requests upon publication of theEndpoint
by means of thepublish(String address)
method. If publishing is carried out using thepublish(Object serverContext))
method, an implementation MAY use the specified executor or another one specific to the server context being used.<> Conformance (Default Executor): If an executor has not been set on an
Endpoint
, an implementation MUST use its own executor, ajava.util.concurrent.ThreadPoolExecutor
or analogous mechanism, to dispatch incoming requests.
Also, section 5.2.2 references 5.2.7 near the end of the section:
5.2.2 Publishing
...
An
Endpoint
will be typically invoked to serve concurrent requests, so its implementor should be written so as to support multiple threads. Thesynchronized
keyword may be used as usual to control access to critical sections of code. For finer control over the threads used to dispatch incoming requests, an application can directly set the executor to be used, as described in section 5.2.7.
I realize this probably doesn't answer your question exactly, but hopefully it points you in a direction that you can get the answer you are looking for.
An Executor needs to be set in order to make an Endpoint multi-threaded. A simple multi-threaded Executor would be the fixed thread pool Executor.
endpoint.setExecutor(Executors.newFixedThreadPool(4));
This will allow your WebService to accept 4 connections simultaneously. But make sure your Service is thread safe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With