Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javax.xml.ws.Endpoint how does it deal with multiple connections?

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?

like image 652
Thomas Winsnes Avatar asked Jun 19 '10 02:06

Thomas Winsnes


People also ask

What is use of javax XML WS endpoint class?

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.

What is BindingProvider in Web service?

The BindingProvider interface provides access to the protocol binding and associated context objects for request and response message processing.

Which is known as the set of APIs in Java used to create the web services in the form of XML?

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.


2 Answers

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 a java.util.concurrent.Executor. The executor will then be used to dispatch any incoming requests to the application. The setExecutor and getExecutor methods of Endpoint 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 the setExecutor method, then an implementation MUST use it to dispatch incoming requests upon publication of the Endpoint by means of the publish(String address) method. If publishing is carried out using the publish(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, a java.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. The synchronized 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.

like image 156
laz Avatar answered Nov 03 '22 00:11

laz


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.

like image 44
Flow Avatar answered Nov 03 '22 00:11

Flow